← Object-Oriented Programming learning path
Object-Oriented Programming · Module 6 of 10

Polymorphism

One interface, many forms.

📖 Key ideas

  1. Polymorphism lets the same call behave differently by object type.
  2. Compile-time: method overloading (same name, different parameters).
  3. Run-time: method overriding (child redefines parent method).
  4. Example: shape.area() works for Circle and Square.
  5. 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