Consider the following class...
class Main{ /* ww w. j a v a 2s.com*/ void m (int... x) { System.out.println ("In ..."); } //1 void m (Integer x) { System.out.println ("In Integer"); } //2 void m (long x) { System.out.println ("In long"); } //3 void m (Long x) { System.out.println ("In LONG"); } //4 public static void main (String [] args){ Integer a = 4; new Main ().m (a); //5 int b = 4; new Main ().m (b); //6 } }
What will it print when compiled and run?
Select 2 options
Correct Options are : A D
The compiler always tries to choose the most specific method available with least number of modifications to the arguments.
Widening is preferred to boxing/unboxing, which in turn, is preferred over var-args.