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.
39 lines
690 B
39 lines
690 B
// 图形父类
|
|
class Shape {
|
|
public void draw() {
|
|
System.out.println("绘制图形");
|
|
}
|
|
}
|
|
|
|
// 圆形子类
|
|
class Circle extends Shape {
|
|
@Override
|
|
public void draw() {
|
|
System.out.println("绘制圆形");
|
|
}
|
|
}
|
|
|
|
// 矩形子类
|
|
class Rectangle extends Shape {
|
|
@Override
|
|
public void draw() {
|
|
System.out.println("绘制矩形");
|
|
}
|
|
}
|
|
|
|
// 测试主类
|
|
public class ShapeTest {
|
|
|
|
// 题目要求的方法
|
|
public static void drawShape(Shape s) {
|
|
s.draw();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Shape c = new Circle();
|
|
Shape r = new Rectangle();
|
|
|
|
drawShape(c);
|
|
drawShape(r);
|
|
}
|
|
}
|
|
|