Skip to main content

Inheritance

Inheritance in OOP is a concept that allows inheriting the features of other classes. This is a real-life concept where a child inherits its properties from his parents, in a similar way a child class inherits the features of its parent class.

  • The parent class is called super or base class.
  • The child class is called sub or derived class.

In OOP, the sub class inherits the properties from its super class. The inheritance is achieved in 4 different ways

Single inheritance

The derived class inherits the properties of the base class. This enables the usability of code and allows adding new features in derived class without affecting the base class.

Multi-level inheritance

A class inheriting from derived class creates multiple inheritance. A class has more than one parent and can inherit their functions.