← All Exercises
Python Class Inheritance
intermediatepython
Background
Inheritance enables code reuse and polymorphism, allowing subclasses to extend or modify parent class behavior.
Problem
Create an Animal base class with a speak method, and Dog and Cat subclasses that override speak with specific sounds, using super() in constructors.
Input
No input; classes are defined and instantiated.
Output
Class instances with inherited and overridden methods.
Sample tests
Sample 1
Input: Dog("Rex").speak()Expected: "Rex says Woof!"
Your solution
Learning objective
Learn class inheritance, method overriding, and super() usage in Python.