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.
17 lines
604 B
17 lines
604 B
// 5. 主类,包含 main 方法进行测试
|
|
public class ShapeTest {
|
|
public static void main(String[] args) {
|
|
// 创建对象
|
|
Shape1 circle = new Circle();
|
|
Shape1 rectangle = new Rectangle();
|
|
Shape1 generalShape = new Shape1();
|
|
|
|
// 创建工具类对象
|
|
ShapeDrawer drawer = new ShapeDrawer();
|
|
|
|
// 调用 drawShape 方法,体现多态
|
|
drawer.drawShape(generalShape); // 输出:绘制形状
|
|
drawer.drawShape(circle); // 输出:绘制圆形
|
|
drawer.drawShape(rectangle); // 输出:绘制矩形
|
|
}
|
|
}
|