class Rectangle{
double width = 1;
double height = 1;
// Rectangle rectangle = new Rectangle();//无参构造
public Rectangle(double width,double height) {
this.width = width;
this.height = height;
}
public double getArea() {
return width*height;
}
public double getPerimeter() {
return (2*width)+(2*height);
}
}
PTA习题 6-2 设计一个矩形类Rectangle
最新推荐文章于 2024-01-13 18:54:18 发布