Multi Level Inheritance in C++


derived class is created from another derived class is called Multi Level Inheritance 

Multiple Inheritance Example:

#include<iostream>

using namespace std;

class Parent{

               public:

                               Parent(){

                                              cout<<"This is a Parent class "<<endl;

                               }

};

class Child1: public Parent{

               public:

                               Child1(){

                                              cout<<"This is a Child1 class "<<endl;

                               }

};

class Child2: public Child1{

               public:

                               Child2(){

                                              cout<<"This is a Child2 class "<<endl;

                               }

};

int main(){

               Child2 obj; 

}

Output:

This is Parent class

This is Child1 class

This is Child2 class

Post a Comment

0 Comments

Close Menu