public class SealedDemo {
    sealed interface Shape permits Circle, Square {}
    record Circle(double radius) implements Shape {}
    record Square(double side) implements Shape {}

    static double area(Shape shape) {
        if (shape instanceof Circle c) {
            return Math.PI * c.radius() * c.radius();
        }
        if (shape instanceof Square s) {
            return s.side() * s.side();
        }
        throw new IllegalArgumentException("unknown shape");
    }

    public static void main(String[] args) {
        System.out.println(area(new Circle(1)));
        System.out.println(area(new Square(2)));
    }
}
