Sobes.tech
Junior — Middle

Kas saaksite loetleda Kotlinis kasutatavaid klassitüüpe?

sobes.tech AI

Vastus AI-lt

In Kotlin, the following class types are used:

  • Regular classes — standard classes for describing objects.
  • Abstract classes — classes that cannot be instantiated directly, may contain abstract methods.
  • Interfaces — describe a set of methods and properties that must be implemented by classes.
  • Object declarations — singletons, create a single instance of a class.
  • Companion objects — an object inside a class that allows creating static members.
  • Data classes — classes intended for storing data, automatically generate methods like equals, hashCode, toString, and copy.
  • Nested and inner classes — classes declared within other classes; inner classes have a reference to the outer class.
  • Sealed classes — classes with a limited set of subclasses, useful for expressing restricted hierarchies.

Example of a data class:

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