[Logo]
Forums Register Login
problems in method overloading
class Array{
static void display(float i){
System.out.println("float");
}
public static void main(String[] arg){
long l=400000000000l;
display(l);
}
}

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).
This problem was discussed some days ago in this Thread. There is also a link that seemed to clarify the problem: http://stackoverflow.com/questions/1293819/why-does-java-implicitly-without-cast-convert-a-long-to-a-float
thanks Thorsten....
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 788 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 19, 2018 09:45:29.