CPP Programming
About Lesson

When a class is derived from another class that is already derived from another class, this is known as multi level inheritance.  In this case, one child class, its immediate parent class and parent class of its parent (grand parent class) like many levels can be seen.

 

//example code showing how multi level inheritance can be established

#include <iostream>

using namespace std;

 

class man {

public:

    char name[10]=”Raju”;

    float height=5.8;

};

 

class husband: public man {

public:

      char wife[10]=”Rani”;

};

 

class father: public husband {

public:

    char child[10]=”Yuvi”;

 

};

 

 

int main(void) {

    father obj;

    cout<<“Name: “<<obj.name<<endl;

    cout<<“Height: “<<obj.height<<endl;

    cout<<“wife name: “<<obj.wife<<endl;

    cout<<“child name: “<<obj.child<<endl;

    return 0;

}

You cannot copy content of this page