I was reading the Java Tutorial and had a question about explicit constructor invocation. First of all, here are the fields and constructors as written in the tutorial, plus another constructor I added:
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;
}
In the default constructor, "this(0,0,1,1);" line doesn't specify the types of the 0s. My question is, why doesn't it go to the third constructor I wrote (with 'short' types) or give errors. When I print out the object's 'x' value, I always get 0 and never 4. How does Java decide to go with the 'int'?