Variables in Kolin Android Studio
Declaring of Variables in Kotlin using Android Studio:
val is used to declare a variable in Kotlin
val is immutable i.e. it cannot be reassigned after it is declared.
Method 1:
val name: String
val number: int
val number: float
val number: double
val state: boolean
Now declaring values for variables
name="Tech Uplift"
number= 1
number= 1.006
number= 1.5
state=false
In the method above variables are explicitly declared .Saying that the type of variable should be declared first.
Method 2:
In this method variables are not declared explicitly.
They are straight way declared.
val name="Tech Uplift"
val number= 1
val number= 1.006
val number= 1.5
val state=false
Similarly var can be used
but var is mutable
can be changed even after it is declared.
val is used to declare a variable in Kotlin
val is immutable i.e. it cannot be reassigned after it is declared.
Method 1:
val name: String
val number: int
val number: float
val number: double
val state: boolean
Now declaring values for variables
name="Tech Uplift"
number= 1
number= 1.006
number= 1.5
state=false
In the method above variables are explicitly declared .Saying that the type of variable should be declared first.
Method 2:
In this method variables are not declared explicitly.
They are straight way declared.
val name="Tech Uplift"
val number= 1
val number= 1.006
val number= 1.5
val state=false
Similarly var can be used
but var is mutable
can be changed even after it is declared.
Comments
Post a Comment