aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method overloading Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Method overloading Problem" Watch "Method overloading Problem" New topic
Author

Method overloading Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

TestCafe 3.0 by sahir shah


ANswer:

This code will fail to compile because the
compiler cannot resolve the method call here.

why cannot resolve method call ??
can't it call the method with int as arguments as they much narrower er


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 244

Mohit... Your answer is right... The answer given above is wrong... Better you execute the program and come to conclusion... Believing the answer theortically does not lead to exploration of concepts...


SCJP 6 [SCJP - Old is Gold]
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

This will compile fine, but, the answer is some what different. The concept behind this is called as choose the most specific method invocation.
If more than one member method is both accessible and applicable to a method invocation, it is necessary to choose one to provide the descriptor for the run-time method dispatch. The Java programming language uses the rule that the most specific method is chosen.

The informal intuition is that one method is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error.


Have a look on this JLS


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Trivikram Kamat
Ranch Hand

Joined: Sep 26, 2010
Posts: 155
Hey, the code does compile and displays 20 in the output which is returned by method public int area(int length , int width);
Java version 1.6.0_21


OCPJP6
 
I agree. Here's the link: jrebel
 
subject: Method overloading Problem
 
Similar Threads
ques from overloading
NoSuchMethodError
Overloaded method
Ambiguous Method
Inheritance Doubt