Hybrid inheritance
Hybrid inheritance is a combination of two or more inheritances.
Example:1
A & B: single inheritance
B,C & D: Multiple inheritances
Example:2
A & B: Single inheritance
C & D: Single inheritance
B, D & E: multiple inheritance
Example:3
A, B, C: hierarchical inheritance
B, C, D: Multiple inheritances
From the above figure we have
Class “D” inherits the properties of class “A” two times firstly through class “B” and secondly through class “C”.
Multipath inheritance
When a class inherits the properties of another class through two or more different paths then, it is known as multipath inheritance.
The syntax for defining a base class and derived class
class classA
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
class classB:private/protected/public classA
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
class classC
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};
//derived class
class classD : private/protected/public classB, private/protected/public classC
{
private:
Variables/methods;
protected:
Variables/methods;
public:
Variables/methods;
};