Polymorphism in object-oriented programming allows for methods with the same name to behave differently depending on the object that calls them.
In this example, all three classes—Car, Ship, and Airplane—have a method called move(). However, when you call move() on each object, it executes the appropriate behavior specific to that class. This is polymorphism in action: the same method name (move()) being used across different classes, but with each class providing its own implementation.
Output:
Car moves on roads. Ship moves on water. Airplane flies in the sky. |