Q:

Write a program in kotlin to differentiate between val and var

belongs to collection: Kotlin programming Exercises

0

Write a program in kotlin to differentiate between val and var

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Solution:

fun main(args : Array<String>)  {  
	var x: String  = "Tiger"
    x = "Lion" //valid
    val y: String  = "Cow"
    y = "Dog" // error
    println("$x  and $y")
}

Output:

Error:(5, 5) Kotlin: Val cannot be reassigned

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a program in kotlin to map the following ... >>
<< Write a program to print numbers from 10 to 1 usin...