Module: | Classes, Objects, OOPs & Inheritance
Q25: Consider the following statements regarding final methods and Method Hiding:
1. Methods explicitly declared with the final keyword are permanently locked and cannot be overridden by any inheriting subclass under any circumstances.
2. If a subclass declares a static method with the exact same signature as a static method in the parent class, it is classified as Method Hiding rather than Method Overriding.
3. The JVM processes Method Hiding by utilizing Dynamic Method Dispatch, resolving the correct static method at runtime based on the instantiated object's memory heap type.
Which of the above statements is/are correct?
2. If a subclass declares a static method with the exact same signature as a static method in the parent class, it is classified as Method Hiding rather than Method Overriding.
3. The JVM processes Method Hiding by utilizing Dynamic Method Dispatch, resolving the correct static method at runtime based on the instantiated object's memory heap type.
Which of the above statements is/are correct?
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because Method Hiding does not utilize Dynamic Method Dispatch; instead, the JVM statically resolves the method execution during compile-time based entirely on the reference variable's declared type.Structural Breakdown: Final methods are sealed.
Static methods belong to the class blueprint.
If the Base class has a static display method and the Derived class has a static display method, invoking the method via a Base reference will execute the Base method, entirely ignoring the actual Heap object type.
Historical/Related Context: The distinction between overriding and hiding is a notorious trap in university examinations.
Java implemented the final keyword to provide critical security for core API methods, preventing malicious developers from overriding foundational security checks in classes like java.lang.String.
Causal Reasoning: Method Hiding resolves at compile-time because static methods reside in the Metaspace and are inherently decoupled from object instantiation.
The compiler simply inspects the reference variable, identifies its static blueprint, and binds the instruction path long before the application ever runs.