What is Polymorphism?
Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance.It allows us to perform a single action in different ways.
Types:
class Animal {
public void animalSound() { System.out.println("The animal makes a sound"); }
}class Pig extends Animal {
public void animalSound() { System.out.println("The pig says: wee wee"); }
}
class Dog extends Animal {
public void animalSound() { System.out.println("The dog says: bow wow"); }
}