ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE

A base class method is declared `final` in Java. What does this guarantee about calls to it through a base-class reference, regardless of the object's actual class?

  1. A. It still uses dynamic dispatch, exactly as if it were not final
  2. B. It cannot be overridden by any subclass, so the call always statically resolves to that exact method body, with no possibility of dynamic dispatch to a different implementation
  3. C. Final methods can only be called from within the same package
  4. D. Declaring a method final has no effect on binding at all

Correct answer: B. It cannot be overridden by any subclass, so the call always statically resolves to that exact method body, with no possibility of dynamic dispatch to a different implementation

A final method cannot be overridden anywhere in the hierarchy, so there is only one possible implementation to call; the JVM (and often the JIT) can bind it statically with no virtual dispatch needed.

More OOP with C++ and Java questions

Exams that ask this topic