我在這個網站上發現了以下問題。超載方法
"What happens when we pass int arguments to the overloading method having float
as a parameter for one method and another having double param".
我想我理解的概念,並寫了這個代碼:
public class TestClass {
public static void main(String args[])
{
TestClass t=new TestClass();
t.sum(1/4);
}
void sum(double d)
{
System.out.println("Double==="+d);
}
void sum(int i)
{
System.out.println("Integer==="+i);
}
void sum(short s)
{
System.out.println("Short==="+d);
}
}
據我的瞭解這個網站解釋(如上所述),我認爲這將打印Short===0
,但令我驚訝的是它打印Integer===0
。任何人都可以向我解釋這一點嗎?