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.
43 lines
1.0 KiB
43 lines
1.0 KiB
public class MainFiveBasic {
|
|
public static abstract class Shape {
|
|
public abstract void draw();
|
|
}
|
|
|
|
public static class Circle extends Shape {
|
|
private final Double radius;
|
|
|
|
public Circle(Double radius) {
|
|
this.radius = radius;
|
|
}
|
|
|
|
public void draw() {
|
|
System.out.println("Drawing a circle of radius " + radius);
|
|
}
|
|
}
|
|
|
|
public static class Rectangle extends Shape {
|
|
private final Double side1;
|
|
private final Double side2;
|
|
|
|
public Rectangle(Double side1, Double side2) {
|
|
this.side1 = side1;
|
|
this.side2 = side2;
|
|
}
|
|
|
|
public void draw() {
|
|
System.out.println("Drawing a rectangle of " + side1 + " * " + side2);
|
|
}
|
|
}
|
|
|
|
public static void drawShape(Shape s) {
|
|
s.draw();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Shape circle = new Circle(1.23);
|
|
Shape rectangle = new Rectangle(1.23, 4.56);
|
|
|
|
drawShape(circle);
|
|
drawShape(rectangle);
|
|
}
|
|
}
|
|
|