Inheritance

Inheritance in programming languages is a concept of OOP which supports hierarchical classification and reusability of code. A class is derived from another class and it shares common characteristics with the class from which it is derived.

Derived class is also known as child class or subclass and the class from which it is derived is called base class or parent class or ancestor class or super class. The new class derived generally has more features than the base class.

Inheritance definition
Inheritance is a process through which a class acquires attributes and behavior of another class.

Example of Inheritance in C++

class Vehicle
{
//Attributes (data + functions)
};

class Car : public Vehicle
{
//Attributes (data + functions)
};

class Audi_r8 : public Car
{
//Attributes (data + functions)
};

The example given above shows multi-level inheritance. Class Audi_r8 is inherited from class Car, which in turn is inherited from class Vehicle.

Various forms of inheritance:

  • Single inheritance
  • Multiple inheritance
  • Hierarchical inheritance
  • Multi-level inheritance
  • Hybrid inheritance

Fact: Simula was the first programming language which had inheritance concept.