package com.shape; public class Rectangle extends Shape { private double width; // 宽度 private double height; // 高度 public Rectangle(double width, double height) { if (width <= 0 || height <= 0) { throw new IllegalArgumentException("长和宽必须大于0"); } this.width = width; this.height = height; } public double getWidth() { return width; } public void setWidth(double width) { if (width > 0) this.width = width; } public double getHeight() { return height; } public void setHeight(double height) { if (height > 0) this.height = height; } @Override public double getArea() { return width * height; // 长 × 宽 } }