Java在几乎相同的构造函数之间的差异是什么;显式构造函数调用";?

Java在几乎相同的构造函数之间的差异是什么;显式构造函数调用";?,java,constructor,constructor-overloading,Java,Constructor,Constructor Overloading,我正在阅读Java教程,对显式构造函数调用有一个问题。首先,这里是教程中编写的字段和构造函数,以及我添加的另一个构造函数: private int x, y; private int width, height; public Rectangle() { this(0, 0, 1, 1); } public Rectangle(int width, int height) { this(0, 0, width, height); } public Rectangle(sho

我正在阅读Java教程,对显式构造函数调用有一个问题。首先,这里是教程中编写的字段和构造函数,以及我添加的另一个构造函数:

private int x, y;
private int width, height;

public Rectangle() {
    this(0, 0, 1, 1);
}

public Rectangle(int width, int height) {
    this(0, 0, width, height);
}

public Rectangle(short x, short y, int width, int height) {
    this.x = (int) x+4;
    this.y = (int) y+4;
    this.width = width;
    this.height = height;
}

public Rectangle(int x, int y, int width, int height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}
在默认构造函数中,“this(0,0,1,1);”行不指定0的类型。我的问题是,为什么它不转到我编写的第三个构造函数(使用“short”类型)或给出错误。当我打印出对象的“x”值时,我总是得到0,从来没有得到4。Java是如何决定使用“int”的

在默认构造函数中,“this(0,0,1,1);”行不指定0的类型


那是不正确的说法。整数数值文字(没有后缀)总是
int
s(这就是为什么
3000000000
这样的文字会是编译错误,因为该值对于
int
来说太大了)。因此,选择了最后一个构造函数-
矩形(intx,inty,intwidth,intheight)

好的,但当我将默认构造函数修改为“this((short)0,(short)0,1,1);”时,它仍然会转到最后一个构造函数。@DerivedEngineer否,
这个((short)0,(short)0,1,1)
将调用
矩形(短x,短y,int-width,int-height)
构造函数。你一定弄错了。是的,我弄错了。谢谢。