← Kotlin Programming learning pathKotlin Programming · Module 7 of 10
Classes and objects
Model data with classes, data classes, objects and inheritance.
📖 Key ideas
- class Person(val name: String, var age: Int) — primary constructor.
- data class gives equals, hashCode, toString and copy.
- object creates a singleton; companion object holds static-like members.
- Classes are final by default; use open to allow inheritance.
- 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