// 矩形类,继承抽象类Shape public class Rectangle extends Shape { // 长、宽 private double length; private double width; // 构造方法:初始化长和宽 public Rectangle(double length, double width) { this.length = length; this.width = width; } // 重写getArea方法:矩形面积 = 长 * 宽 @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; } }