← Object-Oriented Programming learning path
Object-Oriented Programming · Module 5 of 10

Inheritance

Reuse and extend existing classes.

📖 Key ideas

  1. Inheritance lets a child class reuse a parent's attributes and methods.
  2. Java: class Dog extends Animal; Python: class Dog(Animal).
  3. Types: single, multilevel, hierarchical, multiple (Python/C++).
  4. super() calls the parent constructor or method.
  5. 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