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...
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here