public class ShapeUtil { // 统一打印面积的静态方法:支持所有Shape子类 public static void printArea(Shape shape) { if (shape == null) { System.out.println("图形不能为空!"); return; } double area = shape.getArea(); System.out.printf("图形面积为:%.2f%n", area); } }