Inheritance and Its Types in Python

 Inheritance:

  • A mechanism in object-oriented programming where one class inherits the attributes and methods of another class.


Types of inheritance:

  1. Single Inheritance
  2. Multiple Inheritance
  3. Multilevel Inheritance
  4. Hierarchical Inheritance
  5. 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 :


Post a Comment

0 Comments