0Pricing
Java Academy · Lesson

Declaring Sealed Types

Restrict who can extend a type.

What Are Sealed Types

A sealed class or interface restricts which other types may extend or implement it. This lets you model a closed set of possibilities that the compiler can reason about.

The Problem It Solves

A normal public class can be subclassed by anyone, anywhere. Sometimes you want exactly three shapes or two payment kinds, with no surprises. Sealing makes that intent explicit and enforced.

All lessons in this course

  1. Declaring Sealed Types
  2. permits Clause
  3. Sealed with Records
  4. Exhaustive switch on Sealed
← Back to Java Academy