0Pricing
Kotlin Academy · Lesson

Primary Constructor and Property Parameters

Declare classes with primary constructors and inline property declarations.

The Primary Constructor

A Kotlin class declares its primary constructor right after the class name in parentheses. No method body — just a parameter list.

Simplest Class

The primary constructor without modifiers is invisible after the class name.

class Greeter(val name: String) {
    fun greet() = "Hello, $name!"
}
fun main() {
    println(Greeter("Ada").greet())
}

All lessons in this course

  1. Primary Constructor and Property Parameters
  2. init Blocks and Initialization Order
  3. Custom Getters and Setters with field
  4. lateinit and Lazy Initialization
← Back to Kotlin Academy