Multilevel inheritance typically means that a class can be derived from a derived class during a C++ program. Therefore, the derived class inherits from a class, which in turn inherits from another class. Hence, the superclass for one is a sub-class for another.
Syntax:
class A
{ .... ... .... };
class B : public A
{ .... ... .... };
class C : public B
{ .... ... .... };
Example:
#include <iostream>
class A
{
public:
void display()
{
cout<<"Base class content.";
}
};
class B : public A
{
};
class C : public B
{
};
void main()
{
C c;
c.display();
getch();
}
From the example above, class B is derived from A, while class C is derived from B. However, an object of class C is defined in the main() function.