This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In this code i see there's a call to an overloaded method,i think it will be called the triple int parameters method because best fits the call, so why the thought of converting? I apologize for my poor english...!
Anything moving in the diredction of the arrows does not require a cast. Anything moving against the arrows requires a cast.
If the order given above is to be taken into account, how could one explain the result of the above program as Hello World! One instead of Hello World! Two because the middle varibale of the method which prints Two is a double.That would be even more precise...or am I missing something here? Thanks in advance Sri
Joined: Jan 03, 2003
Method call conversions always look for the exact data type or a wider one in the method signatures. They will not do narrowing conversions to resolve methods, instead we will get a compile error. so it will go for float other than double.
From the Java Language Specification, Section 15.12:
The Java programming language uses the rule that the most specific method is chosen. The informal intuition is that one method declaration 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.
The method "Two" could not "pass on" the call to the method "One" because it would require an explicit cast of the 2nd parameter from double to float. However, method "One" could "pass on" the call to method "Two", because the compiler can implicitly widen the 2nd parameter from float to a double. Therefore method "One" is more specific than method "Two" and is chosen by the compiler. And it's difficult to see in my browser, but the arguments in the method call are 7L, not 71.
Joined: Jan 08, 2003
Oops, John, Even i thought them to be 71 instead of 7L. my mistake Thanks for the answer Sri