Inheritance
LockedLesson 17 of 60 · OOP · Medium
Finish these first:Classes and Objects →Or pass the tests below to unlock it now.
The big idea
Subclasses reuse and override behaviour. super() calls the parent.
Think of it like this: Think of a Class as a cookie cutter (the blueprint) and each Object as an individual cookie stamped from it — each cookie can have its own frosting (state) while sharing the same shape (methods).
Read the lesson
Subclasses reuse and override behaviour. super() calls the parent. Python supports multiple inheritance via the MRO (Class.__mro__).
class Animal:
def speak(self): return "..."
class Dog(Animal):
def speak(self): return "Woof"
Prefer composition over deep inheritance trees.
Quick check
Before writing code: What should `Square(3).area()` return when your implementation of Inheritance is working?
Your challenge
Create Shape with area() returning 0 and Square(side) overriding area().
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to java.inheritance (85% overlap). Python allows multiple inheritance; Java has single class inheritance + interfaces.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Inheritance.
Learn this first
- Classes and ObjectsNot yet
Opens up next
This is the last lesson in this branch.