aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloaded methods - Boone's Mock Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloaded methods - Boone Watch "Overloaded methods - Boone New topic
Author

Overloaded methods - Boone's Mock Question

Monisha Talwar
Ranch Hand

Joined: Feb 11, 2003
Posts: 102
Question 29: What is the result of executing the following code:

Select the one right answer.
a. 1
b. 2
c. 3
d. 4
e. 5
Ans: C
Explination:
Question 29: c. The method with all double parameters is actually the only version of test() that the Java Virtual Machine can legally coerce the numbers to. The reason the other versions of test() are not invoked is that at least one of the parameters would have to be automatically coerced from a type with greater accuracy to a type with less accuracy, which is illegal. (See chapter 9.)
I still did not understand...Infact I thought the ans would be (a).


Hey! It compiles! Ship it!
Monisha Talwar
Ranch Hand

Joined: Feb 11, 2003
Posts: 102
Should have thought of this earlier.
The 3rd arg is by default an int and so it can be passed into the 3rd method which takes all 3 doubles. Can't go to the 1st method which has the 3rd arg as short.
So the double, long and int are passed to the the double-double-double method...Right?
Carl Sampson
Greenhorn

Joined: Apr 09, 2003
Posts: 22
I would think C is correct because it is the only method where the parameters could be widened in all cases. In all of the other cases the parameter would have to be narrowed which the compiler won't do for you without an explicit cast.
preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93
yeah the main thing to remeber here is that a number no matter if it is the range of short/ byte/ char will still be taken as an int
unless specifically stated
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloaded methods - Boone's Mock Question