Skip to main content

Understanding Inheritance and Its Types In C++

2 min read Updated June 30, 2026
Share:
On this page (5sections)

Inheritance Definition

Inheritance is the concept in which a class derives the characters of another class similar to a child deriving characters from his/her parents.

The new class so formed is called the derived class or child class and the old class from which the characters are derived is the base class or parent class. The derived class derives the characters of the base class using ”:” operator

  • Inheritance helps in code reusability. This not only saves time but also the reliability of the program.
  • Inheritance also reduces the complexity of a program.

How inheritance works in C++

In the below diagram, Class B derives all characteristics of class A. Class B may also have some additional characteristics in addition to the derived characteristics.

Inheritance C++ Base Diagram

Consider the characteristics of a man and a woman. Both have a name, an age, height, and weight. But they also have some characteristics which are different from each other. While trying to implement the same in a program like saving the characteristics of a man and a woman, Inheritance can be used as below :

class Characters {
   String name;
   int age;
   float height;
   float weight;
}

This is the base class. Separate classes can be written for the other classes based on the usage like,

class Man : public Characters {

}

and

class Woman : public Characters{

}

Here both classes Man and Woman inherits/derives all the characteristics of the class Characters, thus Inheritance reuses and reduces the code.

Inheritance In C++

Inheritance Types

  • Single Inheritance
  • Multiple Inheritance
  • Hierarchical Inheritance
  • Multilevel Inheritance
  • Hybrid Inheritance/Virtual Inheritance

Continue learning with these related tutorials and programs:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Understanding Inheritance and Its Types, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses core C++ syntax, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials