Polymorphism means “many forms.” In programming, it refers to the ability of different objects to respond to the same method call in different ways.
Imagine a function called play_sound()
:
All objects (Guitar, Flute, Drum) implement their own version of play_sound()
, even though the function call is the same.
📌 This is polymorphism: same interface, different behavior.
Type | Description |
---|---|
Duck Typing | Behavior depends on method presence, not object type |
Operator Overloading | Same operator works differently for different data types |
Method Overriding | Subclass redefines a method from the parent class |
Method Overloading (limited) | Simulated using default args or *args |
"If it walks like a duck and quacks like a duck, it's a duck."
Imagine two people:
cook()
method.