Advanced·8 min·advanced · oop
Inheritance & super()
Inheritance & super()
A child class inherits every attribute and method of its parent. Override what you want to change.
super()
Calls the parent's version of a method. Use it inside __init__ to delegate setup, and inside overridden methods to extend behavior.
When to use it
- "B is a kind of A" relationships —
Puppy is a Dog - Sharing logic across closely-related types
When NOT to
- Just to share helper code → use composition or a module function
- More than 2–3 levels deep → usually a smell
Try it
- Add a
Catclass with its ownspeak(). - Build a
Petmixin that addsownerto any Animal subclass.