JavaAdvanced#fundamentals#java17

What is the difference between sealed classes and final classes (Java 17)?

A final class cannot be extended at all. A sealed class restricts which specific classes are permitted to extend it via the 'permits' clause, allowing controlled, exhaustive hierarchies while still being extensible by named subclasses.

Example
sealed interface Shape permits Circle, Square {}
final class Circle implements Shape {}
final class Square implements Shape {}

Related Questions

1
JavaIntermediate#fundamentals#java14

What is the difference between switch statement and switch expression (Java 14+)?

Open
2
JavaBeginner#strings#java15

What is text block syntax in Java (Java 15+)?

Open
3
JavaIntermediate#strings

What is the String pool (intern pool)?

Open