Sealed Class

Last updated

What is Sealed Class?

A sealed class in Kotlin represents a restricted class hierarchy. It's used when a value can have one of a limited set of types, but no other types. Essentially, it's an abstract class that restricts which classes can inherit from it. All subclasses of a sealed class must be declared in the same file as the sealed class itself. This restriction enables the compiler to know all possible subtypes at compile time, allowing for exhaustive when expressions.

Free resources to learn Sealed Class

More in stage 30: Coroutines Builders

Sealed Class: common questions

Can I learn Sealed Class in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Sealed Class in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this Sealed Class tutorial for beginners?

It is lesson 89 of 153 in the free Kotlin roadmap, in stage 30, Coroutines Builders. If you are new to Kotlin, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me