Create an Animal ABC
Intermediate · Write the code · from Python Abstract Base Classes: Enforce Interfaces with ABC
From the lesson: Python Abstract Base Classes: Enforce Interfaces with ABC
Imagine you're an architect handing blueprints to a construction crew. The blueprint says "there must be a front door here" and "the roof goes here." The crew can choose the materials and style, but they must include those parts. If they skip the front door, the building inspector will reject the project.
Read the lessonCreate an abstract class called Animal that inherits from ABC. It should have two abstract methods: speak() and move(). Then create a Dog class that inherits from Animal where speak() returns the string 'Woof!' and move() returns 'Runs on four legs'. Finally, create a dog and print both methods.
More Abstract Base Class exercises
- Predict the ABC ErrorIntermediate
- Fix the Broken ABCIntermediate
- Abstract Property: Employee TypesAdvanced
- Refactor to Use ABCAdvanced
All Python exercises · 50 practice problems · Object-Oriented Programming quiz