Hierarcical Inheritance In C++

aimtocode.com

Hierarcical Inheritance ?

In this type of inheritance, more than one sub class is inherited from a single base class. i.e. more than one derived class is created from a single base class.

aimtocode.com

As shown in above block diagram, in C++ hierarchical inheritance all the derived classes have common base class. The base class includes all the features that are common to derived classes.

Syntax:

aimtocode.com

Example 1:



Output :

x: 11
This is a Vehicle
This is a Vehicle
aimtocode.com

Example 2:



Output :

 x: 10
  Enter an integer number: 10
  Square of 10 is: 100
  Enter an integer number: 20
  Cube   of 10 is: 8000
aimtocode.com