Constructors In Kotlin
Answer : Well init is not body of constructor. It is called after primary constructor with the context of primary constructor. As given in Official documentation: The primary constructor cannot contain any code. Initialization code can be placed in initializer blocks, which are prefixed with the init keyword: class Customer(name: String) { init { logger.info("Customer initialized with value ${name}") } } Note that parameters of the primary constructor can be used in the initializer blocks. They can also be used in property initializers declared in the class body: class Customer(name: String) { val customerKey = name.toUpperCase() } In fact, for declaring properties and initializing them from the primary constructor, Kotlin has a concise syntax: class Person(val firstName: String, val lastName: String, var age: Int) { // ... } As per your question you can add a constructor to accept one parameter like following: class Person(name: String, surn...