What is Runtime Polymorphism?
Runtime polymorphism is when the method to execute is determined at runtime based on the actual object type.
What is another name for runtime polymorphism?
Dynamic polymorphism.
Dynamic polymorphism.
Method overriding.
When is method selection decided in runtime polymorphism?
At runtime, not at compile time.
What determines which overridden method is called?
The actual object type, not the reference type.
Example of runtime polymorphism?
Animal a = new Dog(); a.sound(); → Dog’s version runs.
Why is runtime polymorphism useful?
It enables flexible and extensible designs where behavior varies by object type.
Does runtime polymorphism require inheritance?
Yes. It requires a parent-child class relationship.
Does runtime polymorphism work with static methods?
No. Static methods use compile-time binding.
Is runtime polymorphism related to dynamic binding?
Yes. Runtime polymorphism is implemented through dynamic method dispatch.
What is dynamic method dispatch?
JVM decides at runtime which overridden method implementation to call.
Can private methods participate in runtime polymorphism?
No. Private methods cannot be overridden.
Can final methods participate in runtime polymorphism?
No. Final methods cannot be overridden.
What is the difference between compile-time and runtime polymorphism?
Compile-time uses overloading; runtime uses overriding.
Can runtime polymorphism be achieved using data members in Java?
No. Runtime polymorphism applies only to methods, not variables.
Key rule to remember?
Overriding + object type → runtime polymorphism.
Why can’t fields support runtime polymorphism?
Because variable access is resolved at compile time based on reference type, not object type.
What supports runtime polymorphism in Java?
Only overridden instance methods.
What happens when subclass defines a field with same name as parent?
It results in variable hiding, not polymorphism.
What is variable hiding?
It occurs when a subclass declares a field with the same name as a superclass field.
Which value is accessed for hidden variables?
The value is chosen based on reference type, not object type.
Example of variable hiding behavior?
Parent p = new Child(); System.out.println(p.x); prints Parent’s x.
Can fields be overridden?
No. Fields cannot be overridden; only methods can.
Why does Java restrict polymorphism to methods?
Because methods can be dynamically dispatched, while fields are statically resolved.