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.
22 lines
617 B
22 lines
617 B
public class ShapeTest {
|
|
public static void drawShape(Shape s) {
|
|
s.draw();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
// 创建形状对象
|
|
Shape myShape = new Shape();
|
|
Shape myCircle = new Circle();
|
|
Shape myRectangle = new Rectangle();
|
|
|
|
// 测试 drawShape 方法
|
|
System.out.println("测试 Shape 基类:");
|
|
drawShape(myShape);
|
|
|
|
System.out.println("\n测试 Circle 子类:");
|
|
drawShape(myCircle);
|
|
|
|
System.out.println("\n测试 Rectangle 子类:");
|
|
drawShape(myRectangle);
|
|
}
|
|
}
|