ProgrammingHardTCS NQT Prime · Infosys SP

What happens?

What happens?
static void f(String s)  { System.out.print("S"); }
static void f(Integer i) { System.out.print("I"); }
// main:
f(null);
  1. A. Compile error: ambiguous method call
  2. B. Prints S
  3. C. Prints I
  4. D. Throws NullPointerException

Correct answer: A. Compile error: ambiguous method call

null fits both String and Integer, neither is a subtype of the other, so no most specific method exists and compilation fails.

More OOP with C++ and Java questions

Exams that ask this topic