Q:

Write a program in kotlin to differentiate between val and var

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now