CPP Programming
About Lesson

If a single class is derived from more than one parent class, then it is known as multiple inheritance.  The child class can access its parent classes members along with its own members.

//example code showing how multiple inheritance can be established

#include <iostream>

using namespace std;

 

class father {

public:

    char fatName[10]=”Rama Rao”;

};

 

class mother {

public:

      char motName[10]=”Sita Devi”;

};

 

class son: public father, public mother {

public:

    char hisName[10]=”Luv”;

 

};

 

 

int main(void) {

    son sonObj;

 

    cout<<“Name of son: “<<sonObj.hisName<<endl;

    cout<<“father name: “<<sonObj.fatName<<endl;

    cout<<“mother name: “<<sonObj.motName<<endl;

 

    return 0;

}

 

You cannot copy content of this page