← Kotlin Programming learning path
Kotlin Programming · Module 7 of 10

Classes and objects

Model data with classes, data classes, objects and inheritance.

📖 Key ideas

  1. class Person(val name: String, var age: Int) — primary constructor.
  2. data class gives equals, hashCode, toString and copy.
  3. object creates a singleton; companion object holds static-like members.
  4. Classes are final by default; use open to allow inheritance.
  5. Interfaces define contracts; abstract classes share code.
💡 Real-life example: A data class is a printed form: Kotlin fills in the standard fields (equals, copy) for you.
Primary constructorConstructor in the class header
data classClass with generated helpers
objectSingleton declaration
openAllows subclassing