Class Relationships

Aggregation (Has-A relationship)

Inheritance

Inheritance and its benefits
What gets inherited?
Method Overriding
Super Keyword

Understanding Types of Inheritance in Python


Single Inheritance

Definition:

Code Explanation:


Multilevel Inheritance

Definition:

Code Explanation:


Hierarchical Inheritance

Definition:

Code Explanation:


Multiple Inheritance (Diamond Problem)

Definition:

Code Explanation:


Handling the Diamond Problem

Code Explanation:


Conclusion

Inheritance in summary

  • A class can inherit from another class.
  • Inheritance improves code reuse
  • Constructor, attributes, methods get inherited to the child class
  • The parent has no access to the child class
  • Private properties of parent are not accessible directly in child class
  • Child class can override the attributes or methods. This is called method overriding
  • super() is an inbuilt function which is used to invoke the parent class methods and constructor

90 Replies to “Inheritance in Python”

Leave a Reply

Your email address will not be published. Required fields are marked *