← Object-Oriented Programming learning pathObject-Oriented Programming · Module 5 of 10
Inheritance
Reuse and extend existing classes.
📖 Key ideas
- Inheritance lets a child class reuse a parent's attributes and methods.
- Java: class Dog extends Animal; Python: class Dog(Animal).
- Types: single, multilevel, hierarchical, multiple (Python/C++).
- super() calls the parent constructor or method.
- Use "is-a" relationships: a Dog is an Animal.
💡 Real-life example: Inheritance is a child inheriting the family surname and recipes, then adding their own dishes.
InheritanceChild class reuses parent class
SuperclassParent class
SubclassChild class
super()Accesses parent members