belongs to collection: Kotlin programming Exercises
Write a program in kotlin to differentiate between val and var
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Solution:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answerError:(5, 5) Kotlin: Val cannot be reassigned