Kotlin ClassesLesson 22Free preview
Kotlin Constructors
This lesson is part of Kotlin · All levels
Summary
This lesson reviews the Constructor in Kotlin which is divided into Primary Constructor and Secondary Constructor. The primary constructor is declared directly in the header class along with its class name, while additional initialization can be placed within the 'init' block.
Key points
- The primary constructor is written directly next to the class name.
- Properties can be directly declared in the primary constructor with the keyword 'val' or 'var'
- The 'init {...}' block is used to execute the initial initialization logic code
- Secondary constructor is defined by the keyword 'constructor' and is mandatory to delegate to the primary constructor
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.