You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
986 B

/**
* 矩形类,继承Shape,实现面积计算
*/
public class Rectangle extends Shape {
// 长
private double length;
// 宽
private double width;
/**
* 无参构造
*/
public Rectangle() {}
/**
* 带参构造,初始化长和宽
* @param length 长
* @param width 宽
*/
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
/**
* 实现父类抽象方法,计算矩形面积:长×宽
* @return 矩形的面积
*/
@Override
public double getArea() {
return length * width;
}
// Getter和Setter
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
}