Implement a class Animal and then create child classes Dog, Cat, Bird, each having a unique method sound that returns the sound they make.
Example 1:
Input: Dog
Output: "Woof!"
Example 2:
Input: Bird
Output: "Chirp!"
Implement a method sound in each of the child classes that returns the respective sound of the animal.
class Animal:
def sound(self):
pass
class Dog(Animal):
def sound(self):
return "Woof!"
class Cat(Animal):
def sound(self):
return "Meow!"
class Bird(Animal):
def sound(self):
return "Chirp!"
# Test the classes
dog = Dog()
print(dog.sound()) # Output: Woof!
bird = Bird()
print(bird.sound()) # Output: Chirp!
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.