public class ShapeUtil { /** * 统一打印任意图形的面积(多态调用) */ public static void printArea(Shape shape) { System.out.printf("%s 的面积为:%.2f%n", shape.getName(), shape.getArea()); } /** * 找出面积最大的图形 */ public static Shape findLargest(Shape[] shapes) { Shape largest = shapes[0]; for (Shape s : shapes) { if (s.getArea() > largest.getArea()) { largest = s; } } return largest; } }