| Author |
Overloading Methods
|
Ivaturi Srinivas
Ranch Hand
Joined: Jun 03, 2003
Posts: 42
|
|
class X { public int process(int i) { System.out.println("Coming here into int"); return i; } public int process(byte i) { System.out.println("Coming here into byte"); return i; } public int process(short i) { System.out.println("Coming here into short"); return i; } } public class ivaturi { public static void main(String args[]) { X x = new X(); x.process(3); } } If I run the above program I am getting called with int argument method. Why not byte or short. If I explicitly cast the x.process((byte)3) it is taking the byte argument method. Why the JVM impilicitly taking the int argument method when the method call is like this x.process(3); Thanks for your time and help Srinivas Ivaturi
|
 |
Vad Fogel
Ranch Hand
Joined: Aug 25, 2003
Posts: 504
|
|
|
3 is an int literal as far as JVM is concerned.
|
 |
 |
|
|
subject: Overloading Methods
|
|
|