You build two classes, Animal and Dog.
A dog is a kind of animal. So Dog inherits from Animal.
Animal(name)makes an animal with that name.describe()returns "<name> is an animal".Dog(name)makes a dog. It getsnameanddescribe()fromAnimal.- Don't write
describe()again inDog. The inherited one already works. - A dog adds one method.
fetch()returns "<name> fetches the ball".
Each input line is animal or dog, then a name.
For an animal, the test code prints its describe(). For a dog, it prints describe(), then fetch(). Each text goes on its own line.
The starter code spells the methods your language's way. C# has Describe and Fetch.
Example 1:
Input:
dog Rex
animal Tom
Output:
Rex is an animal
Rex fetches the ball
Tom is an animal
Explanation: Rex is a dog. It describes itself and fetches.
Tom is a plain animal. It only describes itself.
Example 2:
Input:
dog Max
dog Bella
Output:
Max is an animal
Max fetches the ball
Bella is an animal
Bella fetches the ball
Explanation: Both dogs describe themselves with the method they inherited.
Example 3:
Input:
animal Rex
dog Rex
Output:
Rex is an animal
Rex is an animal
Rex fetches the ball
Explanation: The two have the same name.
Only the dog fetches.
Constraints:
- A name is one word of 1 to 20 English letters.
- 1 to 100 lines per test case.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
