ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE

In Java, instance method calls (non-static, non-private, non-final) use dynamic dispatch based on the object's actual run-time class. Field access and static method calls instead use:

  1. A. A random choice made at class-loading time
  2. B. Static binding, based on the declared (compile-time) type of the reference expression
  3. C. Dynamic binding, based on the object's run-time class, exactly like instance methods
  4. D. Dynamic binding, but only when the field is declared public

Correct answer: B. Static binding, based on the declared (compile-time) type of the reference expression

Unlike overridden instance methods, Java resolves field access and static methods purely from the reference's compile-time declared type, never from the object's actual run-time class.

More OOP with C++ and Java questions

Exams that ask this topic