Kotlin Program - Study Mode
[#191] What is the equivalent of the following Java expression in Kotlin? int x = a ? b : c
Correct Answer
(B) val x = if (a) b else c
[#192] You have an enum class Signal that represents the state of a network connection. You want to print the position number of the SENDING enum. Which line of code does that? enum class Signal { OPEN, CLOSED, SENDING }
Correct Answer
(D) println(Signal.SENDING.ordinal)
[#193] What is the output of the following code? val list : List<Int> = listof(1, 2, 3)
list.add(4)
print(list)
Correct Answer
(C) It does not compile as List has no add method
[#194] What does the following code print? val listA = mutableListOf(1, 2, 3)
val listB = listA.add(4)
print(listB)
Correct Answer
(A) true
[#195] What is the difference between the declarations of COLOR and SIZE? class Record{
companion object {
const val COLOR = "Red"
val SIZE = "Large"
}
}
Correct Answer
(D) Both are immutable, but the use of the keyword const makes COLOR faster and more space efficient than SIZE