Question | Click to View Answer |
Use the REPL to print the string "greetings". |
println("greetings")
|
What does the following code print? var x: Int = 22
println(x)
|
The variable x is typed as an integer and assigned to the value 22. After the variable is created, it is printed. |
What does the following code print? What is the type of variable y? var y = 99
println(y)
|
The variable y is assigned to the value 99. Since a type is not explicitly set, the type is inferred based on the value. In this case, Scala is a statically typed language and variables can only have a single type that never changes. |
What does the following code print? var aa: String = "hello"
aa = "pretty"
println(aa)
|
|
What does the following code print? var bb: Int = 10
bb = "funny"
println(bb)
|
This code throws an error. The variable |
What does the following code print? val cc: Double = 3.14
println(cc)
|
|
What does the following code print? val dd: Double = 9.99
dd = 10.01
println(dd)
|
This code throws an error. Variables assigned with the This code would not have errored out if the Variables defined with the Variables defined with the |
What is the type of the variable var gg = 8.88
|
|