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.
18 lines
603 B
18 lines
603 B
public class Main {
|
|
public static void main(String[] args) {
|
|
// 1. 创建不同图形对象(多态:父类引用指向子类对象)
|
|
Shape circle = new Circle(2);
|
|
Shape rectangle = new Rectangle(3, 4);
|
|
Shape triangle = new Triangle(5, 4);
|
|
|
|
// 2. 统一打印面积
|
|
System.out.println("=== 圆的面积 ===");
|
|
ShapeUtil.printArea(circle);
|
|
|
|
System.out.println("=== 矩形的面积 ===");
|
|
ShapeUtil.printArea(rectangle);
|
|
|
|
System.out.println("=== 三角形的面积 ===");
|
|
ShapeUtil.printArea(triangle);
|
|
}
|
|
}
|