Kotlin Constructor - Primary, Secondary Constructor and Init Block

139 Просмотры
Издатель
After learning about visibility modifiers, we will move to Kotlin Constructor. A constructor is responsible for constructing the object. In kotlin we have primary constructor, secondary constructor and init block.

Constructor is often used to initialize class members. Every kotlin class has a default constructor available if no constructor is defined.

In this video we will learn about Kotlin Constructor. We will learn how to define and use primary constructor. And as inside primary constructor we cannot write any logic, and to write logic we have init blocks in kotlin, and we will learn about init blocks as well. And finally we will also learn about secondary constructors.

Basically a Kotlin class can have only single primary constructor and as many init blocks and secondary constructors as required.

If you are having difficulties navigating from one lesson to another, then click on this link and it will open the complete playlist of this Kotlin Object Oriented Programming. In this playlist all lessons are already arranged in chronological order.
Категория
Язык программирования Kotlin
Комментариев нет.