CPP Programming
About Lesson

If more than one child classes are derived from single parent class then it is known as hierarchical inheritance.

//example code showing how hierarichal inheritance can be established

#include <iostream>

using namespace std;

 

class parent {

public:

    char name[10]=”Rama Rao”;

};

 

class son: public parent {

public:

      char hisName[10]=”Raju”;

};

 

class daughter: public parent {

public:

    char herName[10]=”Rani”;

 

};

 

 

int main(void) {

    son sonObj;

    daughter dauObj;

 

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

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

    cout<<“Daughter name: “<<dauObj.herName<<endl;

    cout<<“father name: “<<dauObj.name<<endl;

    return 0;

}

You cannot copy content of this page