ProgrammingVery hardWipro NLTH · TCS NQT

What is printed?

What is printed?
static void f(long x)      { System.out.print("long"); }
static void f(Integer x)   { System.out.print("Integer"); }
static void f(int... x)    { System.out.print("varargs"); }
public static void main(String[] a) { f(5); }
  1. A. long
  2. B. Integer
  3. C. varargs
  4. D. Compile error because the call is ambiguous

Correct answer: A. long

Overload resolution tries widening before boxing and varargs, so int widens to long in the first phase.

More OOP with C++ and Java questions

Exams that ask this topic