Answers for "kotlin difference between val and var"

4

what is difference between val and var kotlin

// Kotlin difference between val and var

// val stands for read-only variable, and cannot be changed. (immutable variable)
fun main() {
    val number = 1
    number = 2	 // Not possible.
}
  
// var stands for variable, and can be changed. (mutable variable)
fun main() {
    var number = 1
    number = number + 9
    println(number) // this would return 10, because number got changed
}
Posted by: Guest on December-06-2020
1

kotlin difference between val and var

// Kotlin difference between val and var

// val stands for value, and cannot be changed. (immutable variable)
fun main() {
    var number = 1
}
  
// var stands for variable, and can be changed. (mutable variable)
fun main() {
    var number = 1
    number = number + 9
    println(number) // this would return 10, because number got changed
}
Posted by: Guest on October-15-2020

Code answers related to "kotlin difference between val and var"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language