You must be familiar with the term Inheritance already. As per those biology lessons, inheritance is the transfer of certain characteristics of a parent to their respective offspring, like facial features, behavior, hereditary diseases, immunity, etc.
Similarly, the properties of one class can be transferred from one class to another so that data members, member methods and functions and other properties can be shared among them.
The process of sharing the properties of one class to another class or classes is known as Inheritance.
- The class whose members are being shared is called Parent Class or Base Class.
- The class which has inherited the members is called Child Class or Derived Class.
Inheritance Limits of Access Specifiers:
|Access Specifiers||Presence in Base Class||Presence in Derived Class.|
This means that if Private members are present in base class, they cannot be present in derived class. Similarly, the rest two follows as per the table.
Types of Inheritance:
- Single Inheritance: When a Derived Class is inherited from a single Base Class, it is called Single Inheritance.
- Multiple Inheritance: When a single Derived Class is inherited from multiple Base Class, it is called Multiple Inheritance.
- Hierarchical Inheritance: When multiple Derived Class are inherited from a single Base Class, it is called Hierarchical Inheritance.
- Nested or Multiple Inheritance: When a derived class which had inherited from a Base Class, can be again used as a Base Class for another separate Derived Class, it is called Multiple Inheritance.
- Hybrid Inheritance: When more than one kind of Inheritance systems are used together, it is known as Hybrid Inheritance.