添加一个无参的构造方法并测试
代码如下:
public class Rect {
int x;
int y;
int width;
int height;public Rect(){
this.x = 0;
this.y = 0;
this.width = 0;
this.height = 0;
}
public Rect(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public String toString() {
return "x=" + x + ", y=" + y + ", width= " + width + ", height="
+ height;
}
}
public class TestRect {
public static void main(String[] args) {
Rect r1 = new Rect(100, 200, 50, 60);
System.out.println(r1);
}
}