C++ - INHERITANCE | Types of Inheritance


C++ supports the concept of reusability once a class has been written and tested, it can be adapted by other programmers to suit their requirements. This is basically done by creating new classes, reusing the properties of the existing ones. The mechanism of deriving a new class from an old one is called inheritance. 

The old class is referred to as base class or super class. 

And the new one is called as derived class or subclass.

Types of Inheritance: -

1. Single Inheritance - A derived class with only one base class, is called Single Inheritance.

Single Inheritance
Single Inheritance

2. Multiple Inheritance - A derived class with several base classes, is called multiple Inheritance.

Multiple Inheritance

3. Hierarchical Inheritance - The properties of one class may be inherited by more than one class is called hierarchical Inheritance.

Hierarchical Inheritance
Hierarchical Inheritance

4. Multilevel Inheritance - The mechanism of deriving a class from another derived class is known as multilevel Inheritance.

Multilevel Inheritance
Multilevel Inheritance

5. Hybrid Inheritance - The hybrid Inheritance is a combination of all types of Inheritance.

Hybrid Inheritance
Hybrid Inheritance


1. Base class: - A base class can be defined as a normal C++ class, which may consist of some data and functions. 

Ex - Class Base 
                : : : : : 

2. Derived Class: - 

i). A class which acquires properties from base class is called derived class. 

ii). A derived class can be defined by class in addition to its own detail. 

The general form is - 
Class derived-class-name: visibility-mode base-class-name 

        : : : : : 

The colon indicates that the derived class name is derived from the base-class- name. The visibility-mode is optional and if present it is either private or