Inheritance-Use of constructors in classes-Example done by me

 #include <iostream>


using namespace std;


class MI


{   


    protected:


    int trophies_mi;


    public:


    


    MI(int t)


    {   


        trophies_mi=t;


        cout<<"Mi won cup for "<<trophies_mi<<endl;

        

    }


    void slogan_mi(void)


    {


        cout<<"Duniya hila denge hum"<<endl;


    }



};




class CSK


{


     protected:


    int trophies_csk;


    public:


    


    CSK(int t)


    {   


        trophies_csk=t;


        cout<<"CSK won cup for "<<trophies_csk<<endl;

    }


    void slogan_csk(void)


    {


        cout<<"Whistle podu"<<endl;


    }



};


class IPL:public CSK,public MI{ 

    protected:

    int years=0;

    public:

    IPL(int a,int b,int c):CSK(b),MI(a)

{

    years=c;

}

   void display()

   {

       cout<<"Thank you IPL for entertaining us for last "<<years<<"years"<<endl;

   }


};


int main()

{   

    IPL i(5,3,15);

    i.slogan_mi();

    i.slogan_csk();

    i.display();

    return 0;

}


Comments

Popular posts from this blog

Hackerrank-Accessing Inherited Functions problem-Inheritance

Inheritance- Code with Harry-Lecture 41 solution (Multiple inheritance)