File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Scjp Chapter2 Self Test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Scjp Chapter2 Self Test" Watch "Scjp Chapter2 Self Test" New topic

Scjp Chapter2 Self Test

Srinivas Palam
Ranch Hand

Joined: Oct 20, 2005
Posts: 66

Can someone explain, how the answer is -434. Book explantion was ... In general, overloaded var-args methods are chosen last. Remember that arrays are objects. Finally, an int can be boxed to an Integer and then "widened" to an Object.

I did not get it totally.

Togaf Part 1 and 2
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 1124
Hi Srinivas buddy,
When aa is passed to sifter, sifter(Object o) is chosen over sifter( A[] ... a2) because a var ags method is always the last choice.
When ba is passed, sifter(B[] b1) is chosen over sifter(Object o) because ba matches B[] type. Also, sifter(B[] ...b1) is a var ags method is always the last choice.
Ankit Gareta
Ranch Hand

Joined: Mar 28, 2011
Posts: 67

Hi srinivas,

As Himai said, the precedence for method parameters are described in K&B books and that's are
1) Widening
2) Boxing
3) Variable Args...

--> In sifter(aa) aa is A's array object , it can't do narrowing to convert it to B , it widening to Object (arrays are object) ,so its goes to sifter(Object o) ans set 4
--> In sifter(ba) ba is B's array ojbect, so it goes compatible with sifter(B[] b1) and ans set to 3
--> in sifter(7) , 7 is integer, in this case int box to Integer and then widening to Object so its goes to sifter(Object o) and ans set to 4

Hope that will help you.


OCPJP 6 (91%)
I agree. Here's the link:
subject: Scjp Chapter2 Self Test
It's not a secret anymore!