Inheritance:
- A mechanism in object-oriented programming where one class inherits the attributes and methods of another class.
Types of inheritance:
- Single Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
1. Single Inheritance:
- When a class inherits from only one parent class.
Program:
Output:
2. Multiple Inheritance:
- When a class inherits from more than one parent class.
Program:
Output:
3. Multilevel Inheritance:
- When a class inherits from a parent class, and that parent class is also inherited by another class.
Program:
Output:
4. Hierarchical Inheritance:
- When multiple classes inherit from a single parent class.
Program:
Output:
5.Hybrid Inheritance :
- Hybrid inheritance is a combination of multiple and hierarchical inheritance in a single program. It allows a class to inherit from multiple classes in different ways.
Program :
Output :
0 Comments