---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 20 Edition"
java_version: 20
chapter: "Chapter 13. Binary Compatibility"
section: "13.4.2"
heading: "13.4.2. sealed, non-sealed, and final Classes"
parent: "13.4. Evolution of Classes"
source: https://docs.oracle.com/javase/specs/jls/se20/html/jls-13.html#jls-13.4.2
id: "13.4.2"
url: https://jvm.obfuscated.software/jls/se20/13.4.2.html
raw: https://jvm.obfuscated.software/jls/se20/13.4.2.md
---

# 13.4.2. `sealed`, `non-sealed`, and `final` Classes

## 13.4.2.1. `sealed` Classes

If a class that was freely extensible ([§8.1.1.2](8.1.1.2.md)) is changed to be declared `sealed`, then an `IncompatibleClassChangeError` is thrown if a binary of a pre-existing subclass of this class is loaded and is not a permitted direct subclass of this class ([§8.1.6](8.1.6.md)); such a change is not recommended for widely distributed classes.

Changing a class that was declared `final` to be declared `sealed` does not break compatibility with pre-existing binaries.

Adding a class to the set of permitted direct subclasses of a `sealed` class will not break compatibility with pre-existing binaries.

If a class is removed from the set of permitted direct subclasses of a `sealed` class, then an `IncompatibleClassChangeError` is thrown if the pre-existing binary of the removed class is loaded.

Deleting the `sealed` modifier from a class that does not have a `sealed` direct superclass or a `sealed` direct superinterface does not break compatibility with pre-existing binaries.

If a sealed class C did have a `sealed` direct superclass or a `sealed` direct superinterface, then deleting the `sealed` modifier would prevent C from being recompiled, as every class with a `sealed` direct superclass or a `sealed` direct superinterface must be either `final`, `sealed`, or `non-sealed`.

## 13.4.2.2. `non-sealed` Classes

Changing a class that was declared `sealed` to be declared `non-sealed` does not break compatibility with pre-existing binaries.

Changing a class that was declared `final` to be declared `non-sealed` does not break compatibility with pre-existing binaries.

A `non-sealed` class C must have a `sealed` direct superclass or a `sealed` direct superinterface ([§8.1.1.2](8.1.1.2.md)). Deleting the `non-sealed` modifier would prevent C from being recompiled, as every class with a `sealed` direct superclass or a `sealed` direct superinterface must be either `final`, `sealed`, or `non-sealed`.

## 13.4.2.3. `final` Classes

If a class that was not declared `final` is changed to be declared `final`, then an `IncompatibleClassChangeError` is thrown if a binary of a pre-existing subclass of this class is loaded, because `final` classes can have no subclasses; such a change is not recommended for widely distributed classes.

Deleting the `final` modifier from a class that does not have a `sealed` direct superclass or a `sealed` direct superinterface does not break compatibility with pre-existing binaries.

If a `final` class C did have a `sealed` direct superclass or a `sealed` direct superinterface, then deleting the `final` modifier would prevent C from being recompiled, as every class with a `sealed` direct superclass or a `sealed` direct superinterface must be either `final`, `sealed`, or `non-sealed` ([§8.1.1.2](8.1.1.2.md)).
