5 changed files with 35 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||||
|
package Shape; |
||||
|
|
||||
|
public class Circle extends Shape { |
||||
|
@Override |
||||
|
public void draw(){ |
||||
|
System.out.println("画一个圆形"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
package Shape; |
||||
|
|
||||
|
public class Rectangle extends Shape { |
||||
|
@Override |
||||
|
public void draw(){ |
||||
|
System.out.println("打印一个矩形"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
package Shape; |
||||
|
|
||||
|
public abstract class Shape { |
||||
|
public abstract void draw(); |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,14 @@ |
|||||
|
package Shape; |
||||
|
|
||||
|
public class main { |
||||
|
public static void drawShape(Shape s){ |
||||
|
s.draw(); |
||||
|
} |
||||
|
public static void main(String[] args){ |
||||
|
Shape circle = new Circle(); |
||||
|
Shape rectabgle = new Rectangle(); |
||||
|
|
||||
|
drawShape(circle); |
||||
|
drawShape(rectabgle); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue