1 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||
|
class Shape { |
||||
|
public void draw() {} |
||||
|
} |
||||
|
|
||||
|
class Circle extends Shape { |
||||
|
public void draw() { |
||||
|
System.out.println("Drawing a circle"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
class Rectangle extends Shape { |
||||
|
public void draw() { |
||||
|
System.out.println("Drawing a rectangle"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
class ShapeTest { |
||||
|
public static void drawShape(Shape shape) { |
||||
|
shape.draw(); |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
Circle circle = new Circle(); |
||||
|
Rectangle rectangle = new Rectangle(); |
||||
|
|
||||
|
drawShape(circle); |
||||
|
drawShape(rectangle); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue