Kotlin Program - Study Mode

[#166] Which keyword is used to create a class in Kotlin?
Correct Answer

(A) class

[#167] You are creating a Kotlin unit test library. What else should you add to make the following code compile without error? fun String.shouldEqual(value: String) = this == value
fun main(){
val msg = "test message"
println(msg shouldEqual "test message")
}
Correct Answer

(C) The code is not legal in Kotlin (should be println(msg.shouldEqual("test message")))

[#168] This function generates Fibonacci sequence. Which function is missing? fun fibonacci() = sequence {
var params = Pair(0, 1)
while (true) {
___(params.first)
params = Pair(params.second, params.first + params.second)
}
}
Correct Answer

(B) yield()

[#169] Which line of code shows how to call a Fibonacci function, bypass the first three elements, grab the next six, and sort the elements in descending order?
Correct Answer

(D) Val sorted = fibonacci().drop(3).take(6).sortedDescending().toList()

[#170] How many different kinds of constructors are available for kotlin classes?
Correct Answer

(B) None