Inheritance:
It is a important feature implemented OOP system by which one class can get all of the properties from another one class along with the same. It can take some new property of its own.Syntax:
class derived class name: visibility mode base class name.
{
- - - - - - -
- - - - - - -
- - - - - - -
}
Types of inheritance:
Now class can be derived from an existing class then the new derived class is called derived class or sub-class and the existing class is called base class or super class. And it is said that the sub class inherits from the base class. It is may take place in many terms. Such as:
1. Single inheritance
2. Multiple inheritance
3. Hierarchical inheritance
4. Multi-level inheritance
5. Hybrid inheritance
1. Single inheritance- When a subclass inheritance from one base class, it is known as single inheritance.
X
↓
Y
2. Multiple inheritance- When a subclass inherits from multiple base classes, it is known as multiple inheritance.
X Y
↘ ↙
Z
3. Hierarchical inheritance- When many subclasses inherits from a single base class, it is known as hierarchical inheritance.
W
↙↓↘
X Y Z
4. Multilevel inheritance- The translative nature of inheritance is reflected by this form of inheritance. When a subclass inherits from a class that itself inherits from another class, it is known as multilevel inheritance.
X
↓
Y
↓
Z
5. Hybrid inheritance- When a subclass inherits from multiple base classes and all of the its base classes inherits from a single base class this form of inheritance is known as hybrid inheritance.
In otherwords, The combination of multiple inheritance and hierarchical inheritance is known as hybrid inheritance.
W
↙ ↘
X Y
↘ ↙
Z
No comments:
Post a Comment