*using java* Create a class Animal Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal(String name) //constructor public void makesSound()with the implementation printing out a generic animal sound. Next, override (add) the makesSound()method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don’t make sounds!) Note, you’ll also need a constructor in each of your subclasses which calls super(name) to initialize the common ‘name’ member of Animal. --- Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. ( you should observe the implementation of the makeSound() method called will be: cat -> from Cat class, dog-> from Dog class, beardedDragon -> from Animal class ) --
*using java*
Create a class Animal
Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class:
Member: name
Methods: Public Animal(String name) //constructor
public void makesSound()with the implementation printing out a generic animal sound.
Next, override (add) the makesSound()method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..).
Do not override the makesSound() for your Dragon (bearded dragons don’t make sounds!)
Note, you’ll also need a constructor in each of your subclasses which calls super(name) to initialize the
common ‘name’ member of Animal. ---
Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each.
( you should observe the implementation of the makeSound() method called will be: cat -> from Cat class, dog-> from Dog class, beardedDragon -> from Animal class )
--
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images