Inheritance Definition :
"Derive quality and characteristics from parents or ancestors. Like you inherit features of your parents."
- Example: She had inherited the beauty of her mother.
Inheritance Syntax :
The basic syntax of inheritance is:class DerivedClass : accessSpecifier BaseClassHere, describe the different type of inheritance.
Types of Inheritance :
There are different types of inheritance:
-Single Inheritance
-Multiple Inheritance
-Multilevel Inheritance
-Hierarchical Inheritance
-Hybrid (Virtual) Inheritance
- Single Inheritance :
Single inheritance represents a form of inheritance when there is only one base class and one derived class.
For example, a class describes a Person:
1.1 Simple Inheritance |
- Multiple Inheritance :
Multiple inheritance represents a kind of inheritance when a derived class inherits properties of multiple classes.
For example, there are three classes A, B and C and derived class is D as shown below:
1.2 Multiple Inheritance |
- Multilevel Inheritance :
Multilevel inheritance represents a type of inheritance when a Derived class is a base class for another class.
In other words, deriving a class from a derived class is known as multi-level inheritance.
Simple multi-level inheritance is shown in below image where Class A is a parent of Class B and Class B is a parent of Class C.
1.3 Multiple Inheritance |
- Hybrid Inheritance (also known as Virtual Inheritance)
Combination of Multi-level and Hierarchical inheritance will give you Hybrid inheritance.
1.4 Hybrid Inheritance |
- Hierarchical Inheritance
If one or more classes are derived from one class then it is called hierarchical inheritance.
1.5 Hierarchical Inheritance |