class Animal { public void animalSound() { System.out.println("Animals make sounds lol"); } } class Pig extends Animal { public void animalSound() { System.out.println("The pig goes oink"); } } class Dog extends Animal
class Animal {
public void animalSound() {
System.out.println("Animals make sounds lol");
}
}
class Pig extends Animal {
public void animalSound() {
System.out.println("The pig goes oink");
}
}
class Dog extends Animal {
public void animalSound() {
System.out.println("The dog goes woof");
}
}
public class Main {
public static void main(String[] args) {
Animal myAnimal = new Animal();
Animal myPig = new Pig();
Animal myDog = new Dog();
// animal class method called
myAnimal.animalSound();
// Pig class method called
myPig.animalSound();
// Dog class method called
myDog.animalSound();
}
}
I created a polymorphism program and I want to know is which is the parent class and what is the child...
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images