Polymorphism means code written against one name works with many types, and the right version runs automatically. A loop calling shape.area() gets the circle's formula for circles and the square's for squares.
Languages support several flavours:
Subtype polymorphism: a subclass or implementation supplies its own version, and the object picks at runtime.
Ad-hoc polymorphism: one name, several parameter lists, resolved when the code is compiled. Operator overloading is the same idea.
Parametric polymorphism: generics, where one List<T> works for every element type.
Duck typing: in dynamic languages, any object with the right method fits.
The gain is that adding a type does not mean editing existing branches, so old code stays untouched. The cost is indirection. Reading a call site no longer tells you which method actually runs.
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
When you call shape.area() through a Shape variable, how does the runtime decide which version runs?It dispatches on the object's actual class, not the variable's declared type, typically through a per-class method table called a vtable.
How does compile-time polymorphism differ from runtime polymorphism?The compiler picks an overload from declared types, the runtime picks an override from the object. A Circle held as a Shape gets the Shape overload.
What must an overriding method honour so code written against the base type still works?Name Liskov substitution: accept at least what the base accepts, promise at least what it promises, and throw nothing callers don't expect.
How would you add a new payment type without editing the existing classes?One new class implements the payment interface, and callers that use only the interface stay as they are. The factory or wiring still changes.
When would you choose generics over taking a base-class parameter?Generics keep the exact type, so a List<Circle> returns Circles with no cast. Use subtyping when behaviour varies per type; a bounded T gets both.
What you can say
Polymorphism means I write code against one name, it works with many types, and the right version runs automatically.
If a loop calls shape.area(), circles get the circle formula and squares get the square formula, and the loop never asks which is which.
First there's subtype polymorphism, where each subclass or interface implementation supplies its own version and the object picks it at runtime.
Ad-hoc polymorphism is overloading, one name with several parameter lists where the compiler picks one, and operator overloading works the same way.
Parametric polymorphism is generics, so one List<T> works for every element type, and dynamic languages add duck typing, where any object with the right method fits.
The payoff is that adding a type doesn't mean editing old branches, and the cost is indirection, because a call site no longer tells you which method actually runs.
Weak answers to avoid
Stops at overriding and inheritanceSubtype polymorphism is only one kind. Name overloading, generics and duck typing too, and say whether each is resolved at compile time or at runtime.
Confuses overloading with overridingOverloads differ by parameter list and the compiler picks one; overrides replace a parent's method and the object picks at runtime. Mixing them up is a red flag.
Only says 'many forms'Knowing what the word means shows no understanding. Show one call site running different code per type, then name the kinds and what they cost.
Presents it as all gain, no costPolymorphism adds indirection, since a call site no longer shows which method runs. Name that cost next to the gain of adding types without editing old code.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.