← All Exercises

Sealed Class Hierarchies

intermediatejava~25min

Background

Sealed classes enable exhaustive pattern matching by restricting subtypes to a known set.

Problem

Create a sealed interface with permitted implementations for exhaustive switch handling.

Input

Sealed class hierarchy

Output

Exhaustive subtype handling

Sample tests

Sample 1

Input: sealed Shape permits Circle, Square
Expected: closed hierarchy

Your solution

Learning objective

Learn sealed hierarchies and exhaustive matching