What will be the result of compiling and running the following code?

public class Test {
    public static void main(String... args) {
        test("A", "B");
    }

    public static void test(String... str) {
        System.out.print("A");
    }

    public static void test(String str1, String str2) {
        System.out.print("B");
    }

    public static void test(String str1, String... str2) {
        System.out.print("C");
    }
}
Explanation
Each of the three test() methods is potentially applicable for the call test("A", "B").
Because among them there is only one method with a fixed number of arguments, it is he who will be called.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes