CPP Programming
About Lesson

If a class is derived from more than one parent classes where its parent classes are derived from a single parent, it is known as Hybrid Inheritance.  It can be seen as the combination of hierarchical and multiple inheritances.

//example code showing how multiple inheritance can be established

#include <iostream>

using namespace std;

 

class couple

{

public:

    int yearofMar=1997;

};

 

class father: public couple {

public:

    char fatName[10]=”Rama Rao”;

};

 

class mother: public couple {

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;

    cout<<“year of their parent’s marriage: “<<sonObj.father::yearofMar<<endl;

 

    return 0;

}

You cannot copy content of this page