1 changed files with 40 additions and 0 deletions
@ -0,0 +1,40 @@ |
|||
class Shape { |
|||
public void draw() { |
|||
System.out.println("Drawing a shape"); |
|||
} |
|||
} |
|||
|
|||
class Circle extends Shape { |
|||
@Override |
|||
public void draw() { |
|||
System.out.println("Drawing a circle"); |
|||
} |
|||
} |
|||
|
|||
class Rectangle extends Shape { |
|||
@Override |
|||
public void draw() { |
|||
System.out.println("Drawing a rectangle"); |
|||
} |
|||
} |
|||
|
|||
public class ShapeDemo { |
|||
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(); |
|||
|
|||
System.out.println("Testing Shape:"); |
|||
drawShape(shape); |
|||
|
|||
System.out.println("\nTesting Circle:"); |
|||
drawShape(circle); |
|||
|
|||
System.out.println("\nTesting Rectangle:"); |
|||
drawShape(rectangle); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue