Multilevel inheritance
In multilevel inheritance we have a class which is the base class of another class and at the same time it is the derived class of another class.
• Class “B” is the base class of class “C” and at the same time is the derived class of the class “A”.
• Class “B” inherits the properties of class “A” and class “C” inherits the properties of class “B”, so indirectly class “C” inherits the properties of class “A”. Thus class “C” is also known as the indirect derived class of class “A”.
• Class “B” is the base class of class “C” and class “A” is the base class of class “B” so indirectly class “A” is the base class of class “C”. Thus class “A” is also known as the indirect base class of class “C”.
The syntax for defining a base class and derived class
//base class
class classA
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
//derived class
class classB : private/protected/public classA
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
class classC : private/protected/public classB
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};