import java.awt.geom.Point2D; abstract class Shape { public Point2D center; abstract double getSurface(); public String toString() { return "I am a shape"; } } class Circle extends Shape{ public double radius; double getSurface() { return Math.pow(radius, 2) * Math.PI; } } class Rectangle extends Shape { public double width, height; Rectangle(double a, double b) { width = a; height = b; } @Override double getSurface() { return width * height; } } class Triangle extends Shape { double basis, height; Triangle(double a, double b) { basis = a; height = b; } double getSurface() { return basis * height / 2.0; } } public class ShapeDemo { public static void main(String[] args) { Rectangle s1 = new Rectangle(4, 5); Triangle s2 = new Triangle(3, 2); Shape[] shapes = new Shape[10]; shapes[0] = new Rectangle(4, 5); shapes[1] = new Triangle(4, 12); System.out.println(shapes[0].getSurface()); System.out.println(shapes[1].getSurface()); } }