Practice mode Java

What does the permits clause of a sealed Java class specify?

Correct answer A. The classes allowed to directly extend it

Explanation

A sealed class restricts inheritance, and its permits clause names the classes allowed to be its direct subclasses. Each one must then be declared final, sealed or non-sealed. This closed hierarchy lets the compiler check that a pattern switch covers every case. Sealed classes became a standard feature in Java 17.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.