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.
35 lines
696 B
35 lines
696 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 shape1 = new Circle();
|
|
Shape shape2 = new Rectangle();
|
|
Shape shape3 = new Shape();
|
|
|
|
drawShape(shape1);
|
|
drawShape(shape2);
|
|
drawShape(shape3);
|
|
}
|
|
}
|