Class Inheritance Advanced

Multilevel Inheritance

A class can inherit a class that inherits other class. A long chain can be formed.

Each child in the chain inherits functions from the ones before it (it's parents grandparents etc...).

Here's an example:

Output:

Explanation:

  • There is an inheritance chain: A is inherited by B. B is inherited by C. C is inherited by D.
  • At line 7 class B inherits class A.
  • At line 14 class C inherits class B. Class C inherits the members from B and A. So class C has members - a, b and c.
  • At line 21 class D extends class C. Class D is at the bottom of the inherit chain. So it all functions from A, B and C. Class D has functions printA, printB, printC and printD