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

public class Main { 
    public static void var(int... x)      //1
    { 
        System.out.println("int... x"); 
    } 
    
    public static void var(Object... x)  //2
    { 
        System.out.println("Object... x"); 
    } 

    public static void var(Integer... x) //3
    { 
        System.out.println("Integer..."); 
    } 
 
    public static void main(String... args)
    {  
        int i = 0; 
        Integer i2 = 127; 
        var(i, i2); 
    } 
}
Explanation
Compilation error: ambiguous method. It is unclear, which method shoud be called: should fist argument be boxed into Integer or the second one unboxed to it's int value.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback