Caffeinated Coder
Book an appointment
Lesson 18 · Objects

Inheritance

A class can be built on top of another one. Write class Dog(Animal) and every Dog can use what Animal defines, while Dog adds or replaces only what is different. Step through a ten-line program, pets.py, and watch where Python finds each attribute: __init__ comes from Animal, name lives on the object itself, and Dog's own speak wins over Animal's. That fixed search order is the method resolution order (MRO), and super() lets an override call the parent's version.

14 min11 steps5 questionsIntermediate
Fig 18 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.