Object-oriented programming · 20 / 26 Exercise Medium

Abstract classes

Objective

Create a Python program with an abstract class Animal that has a name and three methods: set_name(name), get_name() and eat(). The eat() method is abstract.

Instructions

  • Create the class Dog, which inherits from Animal and implements eat() by displaying that the dog is eating.
  • In the main program, ask the user for the name of a dog, create a Dog object, give it the name and call get_name() and eat().
Input
Tobby
Output
Tobby
Eating

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise