• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overloading Methods

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3 is an int literal as far as JVM is concerned.
 
reply
    Bookmark Topic Watch Topic
  • New Topic