5 changed files with 36 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@ |
|||
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,名字和文件名完全一致
|
|||
public class ShapeTest { |
|||
public static void drawShape(Shape s) { |
|||
s.draw(); |
|||
} |
|||
|
|||
public static void main(String[] args) { |
|||
Shape circle = new Circle(); |
|||
Shape rectangle = new Rectangle(); |
|||
Shape shape = new Shape(); |
|||
|
|||
drawShape(shape); |
|||
drawShape(circle); |
|||
drawShape(rectangle); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue