Polymorphism

Lesson 14 of 20

One call, many bodies — watch dynamic dispatch pick the right override at runtime, not compile time.

The big picture

Same call, different behavior

Polymorphism means one method call can run different bodies — the OBJECT, not the variable, decides at runtime.

Overriding

A subclass rewrites an inherited method with the same signature — the new body wins.

Dynamic dispatch

At runtime the JVM asks the real object which override to run. That choice is polymorphism.

Parent variables, child objects

Shape s = new Circle() is legal: the variable type is the parent, the object is the child.

Why it helps

One loop can drive a whole zoo of objects — each responds in its own way, no if-chains.