标题: 长方形类的案例 [打印本页] 作者: 气势如虹 时间: 2016-7-5 22:40 标题: 长方形类的案例 class zuoye{
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;
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;
}作者: suming 时间: 2016-7-5 23:03
学习学习