This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problems in method overloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problems in method overloading" Watch "problems in method overloading" New topic

problems in method overloading

Dharmenrda kumar

Joined: May 13, 2011
Posts: 19
class Array{
static void display(float i){
public static void main(String[] arg){
long l=400000000000l;

it's output is float.
my problems is why it not showing compilation error .
because i am sending long type (takes 8 byte) as an argument, but in display() method parameter is of float type(take 4 byte).
according to K&B books -:
"when an exact match isn't found, the JVM uses the method with the smallest argument that is wider than the parameter. "
but in this case float(4 byte) is not wider than the long(8 byte).

OCJP 96%
Thorsten Schneider

Joined: Apr 04, 2011
Posts: 16

This problem was discussed some days ago in this Thread. There is also a link that seemed to clarify the problem:

Dharmenrda kumar

Joined: May 13, 2011
Posts: 19
thanks Thorsten....
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: problems in method overloading
Similar Threads
varargs, overloading and widening
Overloading and method matching question
Widening conversion
K & B typo ?
Need clarification on overloaded method?