Question: NOTE: Without CHANGING, ADDING, or REMOVING anything from Animal and AnimalTest!! Without modifying the provided Animal and AnimalTest classes, write a Cow and a Cat
NOTE: Without CHANGING, ADDING, or REMOVING anything from "Animal" and "AnimalTest"!!


Without modifying the provided Animal and AnimalTest classes, write a Cow and a Cat class so that the AnimalTest displays the following output: My name is Milky: I'm a cow: I go MOO. My name is Meaty: I'm a cow: I go MOO. My name is Hairy: I'm a cow: I go MOO. My name is Kitty: I'm a cat; I go meow. My name is Garfield; I'm a cat; I go meow... 1 public class AnimalTest 2 { 30 public static void main (String[] args) 4 { 5 Animal[] animalArr = new Animal[5]; 6 7 animalArr[0] = new Cow("Milky"); 8 animalArr[1] = new Cow("Meaty"); 9 animalArr [2] = new Cow("Hairy"); animalArr[3] = new Cat("Kitty"); 11 animalArr[4] = new Cat("Garfield"); 12 13 for (Animal animal : animalArr) 14 { 15 System.out.println (animal); 16 } 17 } 18 } 10 1 public abstract class Animal 2 { 3 private String name; 4 50 public Animal(String name) 6 { 7 this.name = name; 8 } 90 public final String getName(). 10 { 11 return name; 12 } 130 public String toString() 14 { 15 return String.format("My name is %s", getName()); 16 } 17 18 public abstract String makeSound(); 19 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
