Inheritance is the most common and exciting feature of C++ which provides the reusability. Reusability means to use what we have rather than develop same again (In oops classes are reused).
- To reuse the existing classes or their features of the class must be extended.
- The class that is already exists, is known as base class/super class. Or class which taking features of existing class is known as child class/sub class/derived class.
- When sub class/base class is inheriting the super class with private access modifier then public members of super class will become private members of derived class.
- When base class is inheriting the super class with public accessible mode then public members of base class will become public that means no change.
- Private data members are not inherited. They wont go to the derived class.
Types of inheritance :
- Single inheritance
- Multilevel inheritance
- Multiple inheritance
- Hierarchical inheritance
- Hybrid inheritance
Single inheritance :
If a class derived from one base class only means only one base class or one child class.