【发布时间】:2015-10-28 03:32:05
【问题描述】:
以下代码执行时没有任何歧义编译错误,输出为“ArithmeticException”。各位大侠能帮我看看原因吗。
class Test {
public static void main(String[] args) throws UnknownHostException, IOException {
testMetod(null);
}
// Overloaded method of parameter type Object
private static void testMetod(Object object) {
System.out.println("Object");
}
// Overloaded method of parameter type Exception
private static void testMetod(Exception e) {
System.out.println("Exception");
}
// Overloaded method of parameter type ArithmeticException
private static void testMetod(ArithmeticException ae) {
System.out.println("ArithmeticException");
}
}
【问题讨论】:
-
问题是为什么 null 被传递为
ArithmeticException而不是Object或Exception。
标签: java oop exception core arithmeticexception