ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
// static methods of the main class:
static void f(int... a)      { System.out.print("V"); }
static void f(int a, int b)   { System.out.print("F"); }
// in main:
f(1, 2);
f(1, 2, 3);
  1. A. Compilation error: ambiguous call
  2. B. FV
  3. C. VV
  4. D. FF

Correct answer: B. FV

Overload resolution tries methods without varargs first, so f(1, 2) matches f(int, int) exactly: F. Only f(int...) can take three arguments: V.

More OOP with C++ and Java questions

Exams that ask this topic