File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scjp Chapter2 Self Test

 
Srinivas Palam
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Himai Minh
Ranch Hand
Posts: 1142
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
Ankit
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic