【发布时间】:2017-11-26 06:54:13
【问题描述】:
当我在下面的代码中运行时,我得到called 作为输出,我想知道为什么不是called new。因为 1 在 short 和 int 范围内。
public class MyClass {
private int x;
public MyClass(){
this(1);
}
public MyClass(int x){
System.out.println("called");
this.x = x;
}
public MyClass(short y){
System.out.println("called new");
this.x = y;
}
public static void main(String args[]) {
MyClass m = new MyClass();
System.out.println("hello");
}
}
【问题讨论】:
标签: java multiple-constructors