Lesson 11: Inheritance — parent and child classes
What if several classes share exactly the same code? Instead of copying — inherit. A child class gets everything the parent knows for free, adding only what's unique to it. It's OOP's most powerful reuse mechanism.
Inheritance is like family traits: a dog is first of all an animal — it inherits everything animals do (eat, sleep), and adds its own (bark).
- inheritance
- A mechanism where a new class receives all the attributes and methods of an existing class, and extends them.
- parent and child class
- The parent class bequeaths; the child class inherits — written as class Dog(Animal):.