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.
19 lines
531 B
19 lines
531 B
/**
|
|
* 测试类:包含drawShape()方法,统一调用draw()
|
|
*/
|
|
public class TestShape {
|
|
// 统一绘制图形的方法
|
|
public static void drawShape(Shape s) {
|
|
s.draw(); // 多态调用:执行子类重写的draw()
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
// 创建不同图形对象
|
|
Shape circle = new Circle();
|
|
Shape rectangle = new Rectangle();
|
|
|
|
// 调用统一方法绘制
|
|
drawShape(circle);
|
|
drawShape(rectangle);
|
|
}
|
|
}
|