BCA / B.Tech 9 min read

Inheritance in C++

What is Inheritance in C++?

Inheritance is an essential concept in C++, allowing one class to use all the properties and methods of another class. This makes code reuse easier, and the program becomes more modular and efficient.

Types of Inheritance in C++
  • Single Inheritance
  • Multiple Inheritance
  • Multilevel Inheritance
  • Hybrid Inheritance
  • Hierarchical Inheritance

1. Single Inheritance

When a derived class inherits from a single base class, it is called Single Inheritance.

2. Multiple Inheritance

When a derived class inherits from two or more base classes, it is called Multiple Inheritance.

3. Multilevel Inheritance

When a derived class inherits from a base class, and then that same derived class becomes a base class for another class, it is called Multilevel Inheritance.

4. Hybrid Inheritance

Hybrid Inheritance occurs when there is a combination of Multiple and Multilevel inheritance.

5. Hierarchical Inheritance

Hierarchical Inheritance occurs when more than one derived class inherits from the same base class.