Multi Level Inheritance
#include <stdafx.h>
#include <iostream>
#include <string>
using namespace std;
class Class1
{
public:
void display1()
{
cout<< "Display of class1" << endl;
}
};
class Class2:public Class1 //Now Class2 contains all the public members of Class1 through simple inheritance.
{
public:
void display2()
{
cout<< "Display of class2" << endl;
}
};
class Class3:public Class2 // Now Class3 contains all the public members of Class1 and Class2 through multi level inheritance.
{
public:
void display3()
{
cout<< "Display of class3" << endl;
}
};
int main()
{
Class3 c3;
c3.display1();
c3.display2();
c3.display3();
return 0;
}
Output:
Display of class1
Display of class2
Display of class3