A subclass listed as non-sealed in a sealed interface's permits clause is unrestricted, so anyone can extend it further, breaking the closed-hierarchy guarantee at that one branch.
sealed interface Shape permits Circle, Square {}
record Circle(double r) implements Shape {}
non-sealed class Square implements Shape {
double side;
Square(double side) { this.side = side; }
}
class Rectangle extends Square {
Rectangle(double side) { super(side); }
}
Shape s = new Rectangle(4);
System.out.println("s is a Square subtype: " + (s instanceof Square));
System.out.println("s is a Rectangle: " + (s instanceof Rectangle));
s is a Square subtype: true
s is a Rectangle: true
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27