If I have the overloaded methods 1 which takes argument as double and int and 2 which takes the argument as double and long and if I invoke the method by passing values 2.0 and 4 which overloaded method will be invoked. Why?Can anybody please explain.Thanks [ May 18, 2004: Message edited by: Barry Gaunt ]
4 or 2 or 3 is int as its in range (else wont compile) 4l or 2l or 3l is long 4.0 or 2.0 or 3.0 is double 4.0f or 3.0f or 2.0f is float [ May 20, 2004: Message edited by: Swamy Nathan ]
Sorry!One more qustion related to this.How about passing a null for object and the overloaded objects take a String or someother object.Can u please expplain?
We were discussing primitives earlier. Objects cannot be overloaded. Methods can.
I guess this is what you wanted to ask:- Lets say we have overloaded methods-method(...) one version of the method takes a String as argument another say takes a Integer as argument.
If your null is anonymous ie you did a method(null); then the compiler will complain about ambiguity. However if the null was a local object reference or a field then it wont complain.
The method will be as per the type of the reference
String s=null;method(s); will invoke the String argument method