What is the sealed class feature introduced in Java 17 and what problem does it solve?

Java Associate Hard

Java Associate — Hard

What is the sealed class feature introduced in Java 17 and what problem does it solve?

Key points

  • Sealed classes restrict inheritance, unlike final classes.
  • Exhaustive pattern matching is enabled by sealed classes.
  • Controlled inheritance hierarchies are maintained with sealed classes.

Ready to go further?

Related questions