What will the following program write to the console?

public class StringTest {
    public static void main(String[] arg){
        test(new String[] { null });
    }
    static void test(Object[] o){
        System.out.print(1);
    }
    static void test(String o){
        System.out.print(2);
    }
    static void test(String...o){
        System.out.print(3);
    }
    static void test(Object...o){
        System.out.print(4);
    }
}
Explanation
Compilation error will occur, because it is not possible to declare a method with a variable number of arguments and with an array of the same type.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback