Question discussion

What is the output of the following Java program?public class Main { static void f(long x) { System.out.print("L"); } static void f(Integer…

1586Medium DSSSB TGT Computer Science 0 replies

What is the output of the following Java program?

public class Main {
    static void f(long x) { System.out.print("L"); }
    static void f(Integer x) { System.out.print("I"); }
    static void f(int... x) { System.out.print("V"); }
    public static void main(String[] args) { f(5); }
}
  • ACompilation error
  • BI
  • CV
  • DL
Correct answer: D

Explanation

Overload resolution tries widening primitive conversion first (int to long), then boxing, and varargs last, so f(long) is chosen.

Discussion 0

Nobody has replied yet. Start the discussion!