Interview Question

What is compile-time vs runtime polymorphism?

Overloads are selected at compile time; overridden instance methods dispatch at run time.

💡 Concept ✅ Quick Revision ☕ Java

Answer

Compile-time polymorphism usually refers to overload selection; run-time polymorphism refers to overridden instance method dispatch. • The compiler chooses an applicable overload from declared types and arguments. • At run time, the receiver object determines the overriding instance method. • Fields and static methods do not use dynamic overriding dispatch.

Example

Code
class A { String value() { return "A"; } }
class B extends A { @Override String value() { return "B"; } }
A item = new B();
System.out.println(item.value());
Output
B

Quick Revision

Overloads are selected at compile time; overridden instance methods dispatch at run time.