Problem Statement
What is a primary constructor in Kotlin?
Explanation
The primary constructor is declared in the class header like class Person open paren val name colon String comma var age colon Int close paren, and parameters can be declared as properties using val or var. You can add initialization code in init blocks that run when the instance is created, in the order they appear in the class body.
The primary constructor cannot contain any code, so init blocks are used for initialization logic like validation or logging. Primary constructors with property declarations make simple data-holding classes extremely concise, eliminating Java's boilerplate of field declarations, getters, setters, and constructor assignments.
