Question discussion

What is the output of the following Java program?public class Main { static int count(int... a) { return a.length; } public static void mai…

2117Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Java program?

public class Main {
    static int count(int... a) { return a.length; }
    public static void main(String[] args) {
        System.out.println(count() + " " + count(1, 2) + " " + count(new int[]{4, 5, 6}));
    }
}
  • A0 2 3
  • B1 2 3
  • C0 2 1
  • DCompilation error
Correct answer: A

Explanation

A varargs method can be called with no argument (length 0), with separate arguments (length 2) or with an int array (length 3).

Discussion 0

Nobody has replied yet. Start the discussion!