Switch pattern matching and a sealed modifier

Report a typo

Will you face an issue in this code?

public abstract sealed class Shape permits Triangle, Square {
    public static void main(String[] args) {
        Triangle triangle = new Triangle();

        System.out.println(printShapeType(triangle)); 
    }

    public static String printShapeType(Shape shape) {
        return switch (shape) {
            case Triangle t -> "The shape is a triangle";
        };
    }
}

final class Triangle extends Shape { }
final class Square extends Shape { }
Select one option from the list
___

Create a free account to access the full topic