| Author |
Method calling
|
Ram Han
Ranch Hand
Joined: Feb 26, 2002
Posts: 48
|
|
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 "); } }
|
 |
 |
|
|
subject: Method calling
|
|
|