aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method calling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Method calling" Watch "Method calling" New topic
Author

Method calling

Ram Han
Ranch Hand

Joined: Feb 26, 2002
Posts: 49
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 " ?


SCJP,SCWCD,IBM 285,MCTS
Philippe Saint-Just
Greenhorn

Joined: Dec 07, 2005
Posts: 15
"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

Joined: Oct 16, 2005
Posts: 146
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.
 
subject: Method calling