Consider the following code:
public class Main{ public void test (){ test1 (10, 20); //1 }/*w w w . j a v a 2 s . co m*/ public void test1 (int i, int... j){ System.out.println ("1"); } public void test1 (int... i ){ System.out.println ("2"); } public void test1 (int i, int j){ System.out.println ("3"); } public static void main (String [] args){ new Main ().test (); } }
What will the program print?
Select 1 option
Correct Option is : C
In cases where multiple methods are applicable, the compiler always calls the most specific one.
In this case, the third one is the most specific one.
If no method is more specific than the other, then the compilation fails.
For example, if the class did not have the third method test1(int i, int j ), then the remaining two methods would have been equally applicable and equally specific.
In that case, it would not compile.