You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
917 B
40 lines
917 B
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);
|
|
}
|
|
}
|