Hi All,
I came across this question in Cathy Siera SCJP book and the answer is really Strange and i dont understand. The question is below.
class A { }
class B extends A { }
public class Comingthru {
static String s ="-";
public static void main(String[] args) {
A[] aa = new A[2];
B[] ba = new B[2];
sifter(aa);
sifter(ba);
sifter(7);
System.out.println(s);
}
static void sifter(A[]... a2) { s += "1"; }
static void sifter(B[]... b1) { s += "2"; }
static void sifter(B[] b1) { s += "3"; }
static void sifter(Object o) { s += "4"; }
}
** I thought the answer is -444 but in the book said answer is -434 and the explanation given is "-434 is correct. In general, overloaded var-args are chosen last. Remember that arrays are objects. Finally an int can be boxed into an Integet and widened into Object " **
** My question is if the first method invocation went to sifter(object o) and the second should also go to sifter(object O) right ? since both are arrays as per the explanation given in the book .Then why the 2nd invocation went to sifter(B[] b1) ?.
Please explain