| Author |
Passing different datatype
|
thomas davis
Ranch Hand
Joined: Feb 01, 2003
Posts: 207
|
|
public void aMethod(short a) { S.O.P("aMethod with short called"); } public void aMethod(int a) { S.O.P("aMethod with int called"); } public void bMethod(float a) { S.O.P("bMethod with float called"); } public void bMethod(double a) { S.O.P("bMethod with double called"); } If I pass aMethod('a'); and bMethod(5.5); Why does it gives result like this : "aMethod with int called" and bMethod with double called
|
 |
Steve Lovelace
Ranch Hand
Joined: Sep 03, 2003
Posts: 125
|
|
aMethod('a') - the compiler will automatically upcast the char to find the most specific of the overloaded methods which will work. In this case it is aMethod(int). Note that aMethod(short) won't work because the high end of char's range (65535) is out of range for a short (-32768 to 32767)bMethod(5.5) - 5.5 is a double (the default type for floating point literals is double), so this one's straightforward. [ September 30, 2003: Message edited by: Steve Lovelace ]
|
The Inner that is named is not the true Inner.
|
 |
 |
|
|
subject: Passing different datatype
|
|
|