黑马程序员技术交流社区
标题:
【构造方法】长方形案例练习
[打印本页]
作者:
Zzzack
时间:
2015-9-27 14:13
标题:
【构造方法】长方形案例练习
class Test_Rectangle {
public static void main(String[] args) {
Rectangle r = new Rectangle(10,20);
System.out.println(r.getLength());
System.out.println(r.getArea());
}
}
class Rectangle {
private int width;
private int high;
private int length;
private int area;
public Rectangle(){}
public Rectangle(int width,int high) {
this.width = width;
this.high = high;
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return width;
}
public void setHigh(int high) {
this.high = high;
}
public int getHigh() {
return high;
}
public int getLength() {
return 2 * (width + high);
}
public int getArea() {
return width * high;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2