Skip to content
CodeKruPro

Which overload does the compiler pick?

QuizMediumJava only

A class has these three methods. What does p(5) print?

static void p(long x)    { System.out.println("long"); }
static void p(Integer x) { System.out.println("Integer"); }
static void p(int... x)  { System.out.println("varargs"); }
  • long
  • Integer
  • varargs
  • It does not compile: the call is ambiguous

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in