You can follow this link for examples.

In short, sealed classes gives you the control of which models, classes etc. that can implement or extend that class/interface.

Example from the link:

public sealed interface Service permits Car, Truck {

    int getMaxServiceIntervalInMonths();

    default int getMaxDistanceBetweenServicesInKilometers() {
        return 100000;
    }
}

This interface only permits Car and Truck to implement it.

Answer from JDTheOne on Stack Overflow
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › language › sealed-classes-and-interfaces.html
Sealed Classes
October 20, 2025 - Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.
🌐
GeeksforGeeks
geeksforgeeks.org › java › sealed-class-in-java
Sealed Class in Java - GeeksforGeeks
2 weeks ago - A sealed class in Java is a class that restricts which other classes can extend it. The permitted subclasses are explicitly specified using the permits clause. This provides more control over inheritance than a normal class.
Top answer
1 of 10
67

You can follow this link for examples.

In short, sealed classes gives you the control of which models, classes etc. that can implement or extend that class/interface.

Example from the link:

public sealed interface Service permits Car, Truck {

    int getMaxServiceIntervalInMonths();

    default int getMaxDistanceBetweenServicesInKilometers() {
        return 100000;
    }
}

This interface only permits Car and Truck to implement it.

2 of 10
38

The JEP 409 explains it as

A sealed class or interface can be extended or implemented only by those classes and interfaces permitted to do so.

A more practical explanation is the following:

The situation in the past was:

  • You could not restrict an interface being extended by another interface
  • You could not constraint which classes where able to implement a specific interface.
  • You had to declare a class as final in order to not be extended by another class. This way no class could extend the declared final class. This was black or white approach.

The current situation with sealed keyword is:

  • You can now restrict an interface being extended by other interfaces and make a rule for only some specific interfaces which will be allowed to extend it.

    Example:

    public sealed interface MotherInterface permits ChildInterfacePermitted {}
    
    //Has to be declared either as sealed or non-sealed
    public non-sealed interface ChildInterfacePermitted extends MotherInterface {}  
    
    public interface AnotherChildInterface extends MotherInterface {} 
    //compiler error! It is not included in the permits of mother inteface
    
  • You can now create an interface and select only specific classes that are allowed to implement that interface. All other classes are not allowed to implement it.

    Example:

     public sealed interface MotherInterface permits ImplementationClass1 {} 
    
     //Has to be declared either as final or as sealed or as non-sealed
     public final class ImplementationClass1 implements MotherInterface {} 
    
     public class ImplementationClass2 implements MotherInterface {} 
     //compiler error! It is not included in the permits of mother inteface
    
  • You can now restrict a class being extended (same as before with final) but you can now allow some specific classes to extend it. So now you have more control as before the keyword final was absolute restricting every class from extending the declared final class

    Example:

    public sealed class MotherClass permits ChildClass1 {}
    
    //Has to be declared either as final or as sealed or as non-sealed
    public non-sealed class ChildClass1 extends MotherClass {} 
    
     public class ChildClass2 extends MotherClass {} 
     //compiler error! It is not included in the permits of MotherClass
    

Important notes:

  • The sealed class and its permitted subclasses must belong to the same module, and, if declared in an unnamed module, to the same package.

    Example:

    Let's say that we have the same unnamed module and the following packages

      -packageA
         -Implementationclass1.java
      -packageB
         -MotherClass.java
    

    or

       -root
          -MotherClass.java
          -packageA
             -Implementationclass1.java
    

    You will get the error Class is not allowed to extend sealed class from another package. So if you have an unnamed module all participating classes and interfaces for the sealed function must be placed exactly on the same package.

  • Every permitted subclass must directly extend the sealed class.

🌐
Medium
medium.com › @kumar_sachin › understanding-sealed-classes-in-java-17-b542550b7d5e
Understanding Sealed Classes in Java 17 | by Sachin Kumar | Medium
February 16, 2024 - In Java 17, a new feature called sealed classes was introduced. Sealed classes provide a mechanism to restrict the inheritance hierarchy for classes and interfaces.
🌐
OpenJDK
openjdk.org › jeps › 409
JEP 409: Sealed Classes
January 27, 2021 - Enhance the Java programming language with sealed classes and interfaces. Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them. Sealed Classes were proposed by JEP 360 and delivered in JDK 15 as a preview feature.
🌐
Neil Madden
neilmadden.blog › 2026 › 04 › 24 › java-sealed-classes-and-exhaustive-pattern-matching
Java sealed classes and exhaustive pattern matching – Neil Madden
April 24, 2026 - Java 17 introduced sealed classes, which allow you to explicitly list the allowed sub-types of an interface or base class. For example, here’s a toy example using a sealed interface and records (inner classes are implicitly added to the permitted ...
🌐
DEV Community
dev.to › diogomoreira › sealed-and-final-in-java-17-4221
Sealed and Final in Java (17+) - DEV Community
February 18, 2024 - Java 17 brought the Sealed Classes feature, which allows greater control over how to structure a project's class hierarchy.
Find elsewhere
🌐
Medium
medium.com › @barbieri.santiago › java-17-sealed-interfaces-c18ab61a0322
Java 17: Sealed Interfaces. The concept of sealed types was… | by Santiago | Medium
December 18, 2024 - Java 17: Sealed Interfaces The concept of sealed types was introduced to restrict which classes or interfaces can extend or implement a given interface or class. This is for maintaining control over …
🌐
9NEXUS
9nexus.com › java-17-exploring-new-features-in-the-latest-release
:Java 17: Exploring New Features in Latest Release
June 13, 2024 - Java 17 introduces sealed classes as a preview feature, expanding on the capabilities introduced in JDK 16. Sealed classes and interfaces provide a more declarative way to restrict which other classes can extend or implement them.
🌐
Iconsolutions
iconsolutions.com › blog › upgrading-to-java17
Java 17, how I learned to stop worrying and love NoSuchMethodError
June 13, 2024 - Well, besides the normal security and supportability reasons for our customers, the main reason a Java upgrade came onto our radar was this announcement in 2022 from Juergen Hoeller stating that Spring 6+ and Spring Boot 3+ will only be supporting Java 17+. Also, there were increasing grumblings and growing dissent among the ranks as they were not able to use some of the cool new features in Java 12→17, such as records, sealed types, switch expressions (to name but a few).
🌐
Nexus Human UK
nexushuman.co.uk › course › migrating-to-java-17-java-17-new-features-and-skills-tt2135.php
Training Course - UK Migrating to Java 17 | Java 17 New Feature
Throughout the course, you'll delve into Java 17's new features, such as the innovative use of Records for data management and the enhanced String and Text Blocks for improved text handling. These topics, along with the introduction of Sealed Classes and the refined approach to Switch Expressions and Pattern Matching, are more than just updates; they are pivotal enhancements that will streamline your coding practice.
🌐
Estafet
estafet.com › the-importance-of-upgrading-java-a-comprehensive-guide
The Importance of Upgrading Java - A Comprehensive Guide — Estafet
January 23, 2024 - Sealed classes and interfaces (Java 17): this feature enables classes and interfaces to restrict which other classes or interfaces may extend or implement them.
🌐
Kcl
blogs.kcl.ac.uk › proged › 2025 › 05 › 02 › a-brief-history-of-java
A Brief History of Java | Programming Education Blog
Anonymous inner classes especially were a syntactical oddity in Java that made code hard to read and clunky to write. Table 7 adds them to our list. More recent language versions added a host of other new constructs. Examples include a new switch statement and switch expressions added in Java 14, text blocks added in Java 15, and records added in Java 16. Java 17 added the concept of sealed classes.
🌐
Glassdoor
glassdoor.co.uk › Community › job-referrals-qif9-5 › hi-everyone-networking-can-be-a-game-changer-in-the-job-search-so-im-reaching-out-to-my-network-have-you-ever-received-a-referral
Hi everyone! Networking can be a game-changer in the job search, so I’m reaching out to my network. Have you ever received a referral or been introduced to a hiring manager for a role you were excited about using this app? If so, I’d love to hear how it happened! | Glassdoor Forum
March 25, 2025 - My experience includes: 1. Drop and hook operations with no-touch freight 2. Hazmat experience delivering diesel fuel and DEF fuel 3. Delivering milk, auto tires, plastics, and other commodities 4. Shuttle driving between plants, dropping off heavy loads and returning with needed empties 5. Running dedicated routes to various locations, including: _Locations_ 1. Archdale, North Carolina 2. Wilkes-Barre, Pennsylvania 3. Hyattsville, Maryland 4. Cumberland, Maryland 5. Indianapolis, Indiana 6. Scranton, Pennsylvania 7. Newark, Pennsylvania 8. Slatington, Pennsylvania 9. Various other locations t
🌐
Dave Gebler's Blog
davegebler.com › post › php › why-i-don-t-like-the-sealed-classes-rfc
Why I don't like the sealed classes RFC - Dave Gebler's Blog
April 26, 2021 - Personally, although I accept my objections are contentious to some (as evident from the internals discussion), I am forced to come to the conclusion there is no benefit to adding a concept of sealed classes to PHP. Languages like Java can at least claim a point for (1) in the above list, because ...
🌐
eBay
ebay.co.uk › media › books, comics & magazines › textbooks, education & reference › adult learning & university › see more beginning java 17 fundamentals : object-orient...
Beginning Java 17 Fundamentals - 9781484273067 9781484273067 | eBay UK
Beginning Java 17 Fundamentals - 9781484273067 - ISBN-13: 9781484273067, 978-1484273067. These basics lead onto the heart of the Java language: object-oriented programming. By learning topics such as classes, objects, interfaces, and inheritance you'll have a good understanding of Java's object-oriented model.
Price: £41.29
🌐
InformIT
informit.com › articles › article.aspx
Interfaces, Lambda Expressions, and Inner Classes | 6.1. Interfaces | InformIT
Records and enumeration classes cannot extend other classes (since they implicitly extend the Record and Enum class). However, they can implement interfaces. ... Interfaces can be sealed.