File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes KS&BB SCJP Study Guide Self Test Chap 2 Question 15 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "KS&BB SCJP Study Guide Self Test Chap 2 Question 15" Watch "KS&BB SCJP Study Guide Self Test Chap 2 Question 15" New topic
Author

KS&BB SCJP Study Guide Self Test Chap 2 Question 15

Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi there,

The answer to question 15 in Chapter 2's Self Test (SCJP Study Guide - Sierra & Bates) says:

In general, overloaded var-args methods are chosen last.


OK. Fair enough. I know that now. I'm worried though that there may be some other rules of this type that I've missed out on, because I don't see where they are covered in the book. I've experimented with some code and as far as I can see, when choosing which overloaded method to run, the JVM chooses the method that has parameters the furthest down the inheritence tree first.

With this in mind my questions are:

1. Why are methods with var args as parameters chosen AFTER ones with Object as parameter. I would have thought that for an array of class A, then the method with parameter (A[]... a2) would be more specific than one with a parameter of (Object 0).

2. Are there any other cases like var-args going last that I need to be aware of?

Cheers

Joe


OCPJP 85%
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
dont worry..we are here...we will make sure you go fully prepared for the exam
http://www.coderanch.com/t/417622/Programmer-Certification-SCJP/certification/Golden-Rules-widening-boxing-varargs


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Phungsuk Wangdu
Ranch Hand

Joined: Nov 04, 2009
Posts: 114
HIIII
just go through chapter 3 of K B then all your doubts about it will be cleared till then remember
1.Widening beats boxing
2 Widening beats var-args
3.boxing beats var-args

in all the var-args are loser they are chosen if no other method is available
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
That's great. Thanks to both of you for your replies.
 
Don't get me started about those stupid light bulbs.
 
subject: KS&BB SCJP Study Guide Self Test Chap 2 Question 15