Question: A java code to run this out put with out changing any things in this two class which are Animal and AnimalTest class My name

A java code to run this out put with out changing any things in this two class which are Animal and AnimalTest class

My name is Milky; Iam a cow ; i got mow My name is Meaty; Iam a cow ; i got mow My name is Hiry; Iam a cow ; i got mow My name is kitty; Iam a cat; i got meooo My name is Getyy; Iam a cat ; i got mewooo

public class AnimalTest { public static void main (String[] args) { Animal[] animalArr = new Animal[5]; animalArr[0] = new Cow("Milky"); animalArr[1] = new Cow("Meaty"); animalArr[2] = new Cow("Hairy"); animalArr[3] = new Cat("Kitty"); animalArr[4] = new Cat("Garfield"); for (Animal animal : animalArr) { System.out.println (animal); } } } ---------------------- public abstract class Animal { private String name; public Animal(String name) { this.name = name; } public final String getName() { return name; } public String toString() { return String.format("My name is %s", getName()); } public abstract String makeSound(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!