What is the result of the following code compilation and execution?

public class Clazz {
    private void process(String... s) {
        System.out.print("*");
    }
    private void process(String s) {
        System.out.print("1");
    }
    private void process(String s, String a) {
        System.out.print("2");
    }
    public static void main(String[] args) {
        Clazz c = new Clazz();
        c.process("asd");
        c.process("asd","asd");
        c.process("asd","asd","asd");
    }
}
Explanation
Methods with vararg-parameters are analysed in the last order by compiler - only if all other methods are not suitable. Process("asd") and process("asd", "asd") will be compiled without errors.

Follow CodeGalaxy

Mobile Beta

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