Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading Methods" Watch "Overloading Methods" New topic
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.
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: Overloading Methods