0
0
Javaprogramming~5 mins

Runtime polymorphism in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is runtime polymorphism in Java?
Runtime polymorphism is when a call to an overridden method is resolved at runtime, allowing a subclass to provide a specific implementation that is used instead of the superclass method.
Click to reveal answer
beginner
How does Java achieve runtime polymorphism?
Java uses method overriding and dynamic method dispatch to achieve runtime polymorphism. The JVM decides at runtime which method to call based on the object's actual type.
Click to reveal answer
beginner
What is method overriding?
Method overriding happens when a subclass provides its own version of a method already defined in its superclass with the same signature.
Click to reveal answer
intermediate
Why can't runtime polymorphism happen with static methods?
Static methods belong to the class, not instances, so they are resolved at compile time, not runtime. Therefore, they cannot be overridden or used for runtime polymorphism.
Click to reveal answer
intermediate
Explain dynamic method dispatch with a simple example.
Dynamic method dispatch means the JVM calls the overridden method of the actual object type, not the reference type. For example, if a superclass reference points to a subclass object, the subclass method runs at runtime.
Click to reveal answer
Which feature allows Java to decide which overridden method to call at runtime?
ADynamic method dispatch
BMethod overloading
CStatic binding
DConstructor chaining
What must be true for runtime polymorphism to occur?
AMethod must be static
BMethod must be final
CMethod must be private
DMethod must be overridden in subclass
Can runtime polymorphism happen with constructors?
AOnly with abstract constructors
BYes, always
CNo, constructors are not inherited
DOnly if constructors are static
What keyword is used to override a method in Java?
A@Override
Boverride
Csuper
Dextends
Which of these is NOT a benefit of runtime polymorphism?
ACode flexibility
BImproved performance by compile-time binding
CEasier code maintenance
DAbility to use superclass references for subclass objects
Describe runtime polymorphism and how Java uses it with method overriding.
Think about how Java decides which method to run when a superclass reference points to a subclass object.
You got /4 concepts.
    Explain why static methods cannot participate in runtime polymorphism.
    Consider when static methods are linked compared to instance methods.
    You got /4 concepts.