Question is from: John Meyers's
SCJP 5 Mock Exam:
class
test {
public static void main (
String [] args )
{
methodOne(20);
}
static void methodOne( long l )
{
System.out.println("long");
}
static void methodOne( float f )
{
System.out.println("float");
}
}
Answer is : long
I agree with the answer but the explanation :"Prints long. It prints long because it is the most specific choice. Likewise between two methods that accept float or double, float will be chosen.": says between a float & double, float will be chosen.I have tried this out with 20.0 but it prints out double.
Here is what i did:
public class PrimitiveMethodCalls {
public static void main ( String [] args )
{
methodOne(20.0);
}
static void methodOne( float l )
{
System.out.println("float");
}
static void methodOne( double f )
{
System.out.println("double");
}
}
Please Explain.
Thanks
Mamta Sharma
[ August 01, 2008: Message edited by: Mamta Sharma ]