This is the second part of the video series on Kotlin language. Read the first part here. In this post, let’s discuss how to declare variables in the language.
You can declare variables using var keyword as shown below.
fun main(args:Array<String>){ var x:Int = 10 var b:Boolean = true var s:String s = "Hello" var nope:Int println(nope)//ERROR }
Variables have to be initialized before they can be used. You can also declare constants using val keyword.
fun main(args:Array<String>){ val y:Int = 20 println(y) y = 21 //ERROR }
You can find the video here.