← Python Intermediate
12 / 25
Lesson 12 — Inheritance
Reuse via subclasses
A subclass is written class Dog(Animal): and gets every method of the base class for free. It can override a method by defining one with the same name — then the subclass version wins. Methods it does not override still come from the base class.
class Shape:
def name(self):
return "shape"
class Square(Shape):
def name(self):
return "square"
Why it matters: inheritance lets you share common behaviour and change only what is different.
Want it another way?
Task
Override speak in Dog so it returns "Woof".
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.