Difference between sealed and final class in Java

4.8k Views Asked by At

I have just read that Java 15 should have sealed classes. jep360 says:

Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.

I thought that this is exactly what a final class does in Java. So now I wonder: What is the difference between a final class and a sealed class?

1

There are 1 best solutions below

0
On BEST ANSWER

final class A {...} means that no class is allowed extend A.

sealed class A permits B {...} means that only B can extend A but no other class is allowed to do that.