Question: **Using java** Given the below program that applies polymorphism: class Animal { public void animalSound() { System.out.println(The animal makes a sound); } } class Horse
**Using java**
Given the below program that applies polymorphism:
class Animal {
public void animalSound() {
System.out.println("The animal makes a sound");
}
}
class Horse extends Animal {
public void animalSound() {
System.out.println("The horse says: neigh neigh");
}
}
class Dog extends Animal {
public void animalSound() {
System.out.println("The dog says: bow wow");
}
}
class MyMainClass {
public static void main(String[] args) {
Animal p= new Horse();
_____(X)______;// this is polymorphic method
p = new Dog();
_____(Y)_____;// this is polymorphic method
}
}
What shall be written in (X) and (Y) if we want to print the methods belong to class Horse and Dog, by using the same object p.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
