Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Types of Inheritance in C++

Inheritance Types in C++

Majorly there are 5 different types of classified Inheritance in C++, which are –

  • Single inheritance
  • Multiple Inheritance
  • Multilevel inheritance
  • Hierarchical Inheritance
  • Hybrid Inheritance
    • Also known as Virtual Inheritance

Note – Many students get confused because there are various nomenclatures for Base and Derived Class in C++. You must remember –

  • Base Class is same as 
    • Parent Class
    • Super Class
  • Derived Class is same as
    • Child Class
    • Sub Class
Types of Inheritance Inheritance in C++ (1)

Single Level Inheritance

In such type of inheritance,  the derived class can only inherit from one base class.

Example – In the image, B(Derived Class) is only inheriting from A (One Base Class)

Types of Inheritance Single Level in C++

MultiLevel Inheritance

In MultiLevel Inheritance, a derived class is inherited from a base class, which in turn is derived from another base class.

Example – In our Example C is derived Class inheriting from B (Base Class to C), which in turn is also a derived Class inheriting from Class A (Base Class to B).

Here Class be Acts has base class to Class C and itself is derived class in relationship with Class A.

Types of Inheritance MultiLevel Inheritance in C++

Multiple Inheritance

In Multiple Inheritance, A derived Class can have more than 1 Base Classes, thus it is deriving properties from various base Classes.

Example – In the image, B is a derived class which is deriving its properties from 3 different base classes, A1, A2 and A3.

Types of Inheritance Multiple Inheritance in C++

Hierarchical Inheritance

It in some terms is opposite of Multiple inheritance. Here a Base Class is parent to various Derived Classes.

Example – In our example, A acts as Base Class to B1, B2 and B3, which all are derived classes of A.

Types of Inheritance Hierarchical Inheritance in C++

Hybrid Inheritance

This is essentially a combination of one or more types of inheritance. 

For Example – Multiple and Hierarchical inheritance combination. 

Types of Inheritance Hybrid Inheritance in C++