3 changed files with 38 additions and 0 deletions
@ -0,0 +1,38 @@ |
|||||
|
package com.example.shape; |
||||
|
|
||||
|
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 circle = new Circle(); |
||||
|
drawShape(circle); |
||||
|
|
||||
|
Shape rectangle = new Rectangle(); |
||||
|
drawShape(rectangle); |
||||
|
|
||||
|
Shape general = new Shape(); |
||||
|
drawShape(general); |
||||
|
} |
||||
|
} |
||||
|
After Width: | Height: | Size: 256 KiB |
Loading…
Reference in new issue