Sobes.tech
Junior — Middle

Can you list the main classes used in Kotlin?

sobes.tech AI

Answer from AI

In Kotlin, main classes can be divided into several types:

  • Regular classes (class) — standard classes for describing objects.
  • data class — classes for storing data with automatically generated methods equals(), hashCode(), toString(), and copy().
  • sealed class — classes with a limited set of subclasses, useful for expressing hierarchies with a fixed number of options.
  • object — singleton objects that are created once and used as global instances.
  • enum class — enumerations for defining a set of constants.

Example of a data class:

data class User(val name: String, val age: Int)

val user = User("Anna", 25)
println(user)