Loading...
Loading...
A pet clinic's app prints one line per animal. Every animal has a name and an age; each kind makes its own sound.
Write a class Animal with private fields name and age, a constructor and String intro(). Write Dog, Cat and Cow that extend Animal, pass the name and age up with super(...), and each add String sound().
dog, cat or cow), a one-word name and an age.name, age a, says sound, with the sound Woof, Meow or Moo.Example
Input
3 dog Bruno 3 cat Kitty 1 cow Gauri 7
Output
Bruno, age 3, says Woof Kitty, age 1, says Meow Gauri, age 7, says Moo
Each kind adds its own sound to the shared intro.
Try the problem first. Open one hint at a time.
intro() lives in Animal, so every child gets it without writing it again.
The fields are private: the child constructors can only set them through super(name, age).
In main, use a Dog variable for a dog, a Cat variable for a cat, and so on.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor