permits is only one way to say what subclasses are permitted. Quoting JEP 409,

When the permitted subclasses are small in size and number, it may be convenient to declare them in the same source file as the sealed class. When they are declared in this way, the sealed class may omit the permits clause and the Java compiler will infer the permitted subclasses from the declarations in the source file. (The subclasses may be auxiliary or nested classes.) For example, if the following code is found in Root.java then the sealed class Root is inferred to have three permitted subclasses:

abstract sealed class Root { ... 
    final class A extends Root { ... }
    final class B extends Root { ... }
    final class C extends Root { ... }
}

Root is automatically inferred to permit A, B, and C.

Having a keyword for sealed allows more flexibility in the language design for permitted subclasses, and makes it easier to tell at a glance if a class is sealed.


Whether sealed or permits are used in any other contexts isn't really relevant. (I don't think they are, although they might be in future language versions.) Other uses of sealed or permits wouldn't affect the design of this part of the language.

Answer from user2357112 on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › core java › sealed classes and interfaces in java
Sealed Classes and Interfaces in Java | Baeldung
December 11, 2025 - The release of Java SE 17 introduced sealed classes (JEP 409). This feature enables more fine-grained inheritance control in Java. Sealing allows classes and interfaces to define their permitted subtypes. In other words, a class or interface can define which classes can implement or extend it.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › language › sealed-classes-and-interfaces.html
Java Language Updates
October 20, 2025 - Like sealed classes, to seal an interface, add the sealed modifier to its declaration. Then, after any extends clause, add the permits clause, which specifies the classes that can implement the sealed interface and the interfaces that can extend the sealed interface.
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.

🌐
TedBlob
tedblob.com › home › java permits keyword
Java Permits Keyword - TedBlob - Technical Posts
January 12, 2022 - We will learn the permits keyword of Java. The reserved permits keyword allows to specify all the subclasses that can extend the sealed
🌐
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.
🌐
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 - The sealed keyword restricts which classes or interfaces can extend/implement a class/interface. These classes/interfaces must be explicitly declared in the permits clause.
🌐
DEV Community
dev.to › adrian_nowosielski_7bd282 › sealed-classes-in-java-21-controlling-class-hierarchies-1moo
Sealed Classes in Java 21 – Controlling Class Hierarchies - DEV Community
October 8, 2025 - A sealed class is declared using the sealed modifier, followed by the permits keyword, which specifies allowed subclasses:
Find elsewhere
🌐
GitHub
github.com › dotnet › csharplang › discussions › 7952
allow permits keyword for sealed class declarations (and interfaces) · dotnet/csharplang · Discussion #7952
Java allows defining sealed classes and interfaces. With JEP-409 Java introduced the ability to specify exceptions (classes that can actually extend/implement the sealed classes/iterfaces) via permits keyword.
Author: dotnet
🌐
Ramesh Fadatare
rameshfadatare.com › home › java permits keyword
Java permits Keyword
July 19, 2024 - The permits keyword in Java, used alongside sealed, allows for defining a controlled and restricted class or interface hierarchy. By specifying the permitted subclasses or implementors, it ensures that the inheritance hierarchy is well-defined and predictable.
🌐
Medium
medium.com › @kaustubh.saha › sealed-classes-and-interfaces-in-java-1d3abba7300c
Sealed classes and interfaces in Java | by Kaustubh Saha | Medium
December 28, 2025 - The sealed keyword (introduced in Java 15 as a preview and finalised in Java 17) is all about control. It allows you to restrict exactly which classes can extend your class or implement your interface.
🌐
Oracle
docs.oracle.com › javase › specs › jls › se16 › preview › specs › sealed-classes-jls.html
Sealed Classes
March 16, 2026 - The changes are the same as those in the first preview of Sealed Classes in Java SE 15, except for minor editorial changes and the following: Clarification of the use of context when applying the lexical grammar, particularly in the identification of contextual keywords (formerly described as "restricted identifiers" and "restricted keywords"). This is detailed in the specification change document Contextual Keywords. The keywords sealed, non-sealed, and permits are now defined as new instances of contextual keywords (3.9).
🌐
HowToDoInJava
howtodoinjava.com › home › java 15 › sealed classes and interfaces
Sealed Classes and Interfaces
December 25, 2022 - Then, after any extends and implements clauses, the permits clause specifies the classes that are permitted to extend the sealed class. The reserved keyword permits lists all the classes that can extend the sealed class directly.
🌐
Rollbar
rollbar.com › home › what are sealed classes in java?
Beginner’s Guide to Sealed Classes in Java | Rollbar
November 10, 2023 - The sealed modifier is used to declare a class as sealed. Additionally, the classes that are permitted to be its direct subclasses are specified using the permits keyword.
🌐
DEV Community
dev.to › myexamcloud › advanced-class-design-using-java-sealed-classes-287m
Advanced Class Design using Java Sealed Classes - DEV Community
November 1, 2024 - Here, the 'permits' keyword is used to specify the classes that are allowed to implement the sealed interface.
🌐
Medium
medium.com › @omerme › sealed-classes-in-java-7afea4872448
Sealed Classes in Java. What are Sealed Classes / Interfaces? | by OmerM | Medium
November 11, 2022 - Let’s assume that we have a base class as BaseClassA and we use the sealed keyword to restrict inheritance from this class. In this case, the permits keyword should also be used to allow the inheritance of permitted class(es).
🌐
Foojay
foojay.io › home › java sealed classes in action: building robust and secure applications
Java Sealed Classes: Building Robust and Secure Applications
March 2, 2023 - In this example, PaymentMethod is a sealed class that permits CreditCard, PayPal, and Bitcoin to extend it. A sealed class can permit any number of classes to extend it by specifying them in a comma-separated list after the permits keyword.
🌐
Medium
rathod-ajay.medium.com › what-are-sealed-classes-in-java-interfaces-in-jdk-17-and-how-to-use-them-4ebf3c0e65b0
What are Sealed Classes in Java & Interfaces in JDK 17, and how to use them. | by Ajay Rathod | Medium
December 25, 2024 - Just like interfaces, classes can be sealed using the “sealed” modifier. To ensure correct syntax, the “permits” clause must be placed after any “extends” or “implements” clauses:
🌐
Medium
medium.com › @firoudreda01 › understanding-sealed-classes-in-java-48a7f3aaad2a
Understanding Sealed Classes in Java | by Firoud reda | Medium
December 1, 2024 - This article explores the implementation, benefits, and practical applications of sealed classes in Java development. Sealed classes restrict which other classes or interfaces can extend or implement them. This feature provides stronger encapsulation and enables more precise type checking at compile time. public sealed class Shape permits Circle, Rectangle, Triangle { protected double area; public abstract double calculateArea(); } public final class Circle extends Shape { private final double radius; public Circle(double radius) { this.radius = radius; } @Override public double calculateArea() { return Math.PI * radius * radius; } }
🌐
JDriven
jdriven.com › blog › 2021 › 10 › Sealed-classes
Sealed classes in Java 101 - JDriven Blog
October 19, 2021 - A sealed class can also contain ... are not in the same file. For this we need to use the new permits keyword which we can use to add classes that are in the same module or package....