Week 15- OOP Chapter 11- Polymorphism-1
Week 15- OOP Chapter 11- Polymorphism-1
m
OOP - Chapter 11
Polymorphism
•Polymorphism allows objects of different classes to be
used, while still maintaining their own unique behavior.
This means that objects of different classes can respond
to the same message or method in different ways.
void eat() {
System.out.println("Lions eat flesh Animal a1 = new Lion();
because they are carnivore"); a1.eat(); // It will call eat()
} method of Lion class because the
} reference variable is pointing
towards the object of Loin class.
}
}