4 changed files with 32 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||||
|
public class Circle extends Shape { |
||||
|
@Override |
||||
|
public void draw() { |
||||
|
System.out.println("绘制一个圆形"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
public class Rectangle extends Shape { |
||||
|
@Override |
||||
|
public void draw() { |
||||
|
System.out.println("绘制一个矩形"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
public class Shape { |
||||
|
public void draw() { |
||||
|
System.out.println("绘制一个形状"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
public class TestShape { |
||||
|
|
||||
|
public static void drawShape(Shape s) { |
||||
|
s.draw(); |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
Shape shape = new Shape(); |
||||
|
Circle circle = new Circle(); |
||||
|
Rectangle rectangle = new Rectangle(); |
||||
|
drawShape(shape); |
||||
|
drawShape(circle); |
||||
|
drawShape(rectangle); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue