Skip to main content
PreparationZone Logo
PreparationZone
Back to Fundamentals

Fundamentals · Medium · Free

Explain compile-time vs runtime polymorphism with examples.

FresherFundamentalsOOP & Language Fundamentals
Model answer

Compile-time vs runtime polymorphism

Compile-time (static): method overloading—compiler picks signature by argument types. Runtime (dynamic): method overriding—virtual dispatch calls the object's actual class method.

java
void print(int x) { }      // overload
void print(String s) { }

Animal a = new Dog();
a.speak(); // runtime — Dog.speak()
  • Overloading: same name, different parameters—resolved at compile time.
  • Overriding: subclass replaces parent method—needs compatible signature + @Override.
Draw a tiny class diagram: Shape.draw() → Circle vs Square.