Skip to main content

Classes for Kotlins

Kotlin classes are the building blocks for modelling data and behaviour, covering regular classes, objects, interfaces and generics. They define how state is stored through primary constructors and properties, and how types are shared and reused in a program, including data classes, sealed classes and companion objects.

Stage: Language · Part of the Kotlin roadmap · Last reviewed 19 November 2026

What to learn in Classes

Classes interview questions

What is a data class and when should you use it?

A data class is a class meant to hold data. The compiler generates equals, hashCode, toString, copy and componentN functions from the primary constructor properties. Use it for DTOs, value holders and API models, not for classes with rich behaviour or identity-based equality.

Why use a sealed class or sealed interface?

A sealed type restricts its subclasses to a known set in the same package and module. A when expression over it can be checked for exhaustiveness by the compiler, so adding a new case forces you to update every place that handles it.

Where Classes fits in the Kotlin roadmap

Classes belongs to the Language stage (beginner level), which takes about 22 hours. Kotlin basics.

Back to the full Kotlin roadmap