← Object-Oriented Programming learning pathObject-Oriented Programming · Module 6 of 10
Polymorphism
One interface, many forms.
📖 Key ideas
- Polymorphism lets the same call behave differently by object type.
- Compile-time: method overloading (same name, different parameters).
- Run-time: method overriding (child redefines parent method).
- Example: shape.area() works for Circle and Square.
- Enables flexible, extensible code.
💡 Real-life example: Polymorphism is a "play" button: it plays music on a phone, video on a TV, each in its own way.
PolymorphismSame interface, different behaviour
OverloadingSame name, different parameters
OverridingSubclass redefines a method
Dynamic dispatchChoosing method at runtime