File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method calling

 
Ram Han
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Inttest {
public static void main(String a[]){
Inttest t=new Inttest();
t.m1(0);
}
public void m1( int s){
System.out.println("Int ");
}
public void m1( short s){
System.out.println("Short ");
}
}


Here the output is printed as "Int "

Why not " Short " ?
 
Philippe Saint-Just
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Generally speaking, a series of digits with no decimal point is typed as an integer."

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html
 
vipul patel
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read:
While matching the arguments of overloaded methods, compiler performs the closest match.

Literal 0, is considered as an integer. because by default all integral number literals are treated as integer only.

do some change as follow. it will print 'short'.


class Inttest
{
public static void main(String a[])
{
Inttest t=new Inttest();
t.m1((short)0);
}
public void m1( int s)
{
System.out.println("Int ");
}
public void m1( short s)
{
System.out.println("Short ");
}
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic