Variables declaration in kotlin

 

Var :

It is used to declare mutable variable it means it can change the value of variable.

Once we declare variable we can change the data of variable .

Example:

var a=1

In kotlin it is atomatically take datatypes  of the variable .

Also, we can specify data type of variable

Example:

var a:Int =1

Val:

It is used to declare Non mutable variable it means it can not change the value of variable.

It is work as read only variable.

It is same as final keyword in java.

Example :

Val myname=”kotlin”

Lateinit:

Iateinit means late initialization . you have to initialize the variable late .

If you not initialize the variable than throws exceptions  .

Example :

lateinit var myname :String

Comments

Popular posts from this blog

Android Insight Privacy Policy

What is Kotlin ?

What is Realm Database ?