1. val - It is a keyword used to indicate that the variable is a read only variable.
2. var - It is a keyword used to indicate that the variable's value can change.
syntax:
a. declaration
val name: Type
b. initialization
name = value
=============
fun main(){
introducingVariables()
}
fun introducingVariables(){
val name: String
name = "Bell Cranel"
var age = 60
println(name)
age = 40
println(age)
}
==============
Result:
Bell Cranel
40
Note: When I initialize the variable age, I did not include the type since the compiler can inferred the type when I assigned a value to it. So, for constant values, the val keyword should be used.
YOU ARE READING
Kotlin Programming
RandomI have been trying to learn things online. I will put my notes in here. I put things in my own words and i do not copy their programs. I try to do things the right way so that i may learn. Below is the site where i study. Go check this out if you wa...
