Kotlin Program - Study Mode

[#1] What is the difference between a and b? var a: String? = "KotlinProgramming"
var b: String = 'KotlinProgramming"
Correct Answer

(C) b can never become null

[#2] Which is true for the following simple class declaration? class Person (val name: String)
Correct Answer

(A) It is public

[#3] The code below compiled and executed without issue before the addition of the line declaring errorStatus. Why does this line break the code? sealed class Status(){
object Error : Status()
class Success : Status()
}
fun main(){
var successStatus = Status.Success()
var errorStatus = Status.Error()
}
Correct Answer

(A) StatusError is an object, not a class and cannot be instantiated

[#4] The code below is expected to display the numbers from 1 to 10, but it does not. Why? val seq = sequence { yieldAll(1..20) }
.filter { it < 11 }
println(seq)
Correct Answer

(B) To produce result, a sequence must have terminal operation. In this case, it needs a .toList()

[#5] You have an unordered list of high scores. Which is the simple method to sort the highScores in descending order? fun main() { val highScores = listOf(4000, 2000, 10200, 12000, 9030)}
Correct Answer

(C) Public