Classes · Lesson 46 of 76
Inheritance
Inheritance lets a new class build on an existing one — it gets all the parent's data and methods, and can add its own. This avoids repeating code.
Python
Dog is an Animal, so it already has name — we only wrote what's different. This "build on what exists" idea is everywhere in larger programs.
Your turn: add a Cat(Animal) class whose speak() prints that it meows, and call it.
You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →