File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading Methods

 
Ivaturi Srinivas
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3 is an int literal as far as JVM is concerned.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic