What is the output of the following code snippet?
val number = 5 when (number) { 1 -> println("One") 2 -> println("Two") else -> println("Other number") }
Other number
Two
One
Error
What is a field in Kotlin?
A static variable
A backing field for a property
A property declared inside a function
A constant value
Which loop in Kotlin guarantees that the loop body will execute at least once?
while loop
do-while loop
for-each loop
for loop
Which code snippet creates an immutable list of strings in Kotlin?
val names = arrayListOf("Alice", "Bob", "Charlie")
val names = listOf("Alice", "Bob", "Charlie")
val names = mutableListOf("Alice", "Bob", "Charlie")
val names = setOf("Alice", "Bob", "Charlie")
How do you read a line of input from the user in Kotlin?
scanner.nextLine()
read()
readLine()
input()
What is the output of listOf(1, 2, 2, 3).toSet() in Kotlin?
listOf(1, 2, 2, 3).toSet()
{1, 2, 3}
[1, 2, 2, 3]
{1, 2, 2, 3}
[1, 2, 3]
What is the output of the following Kotlin code?
fun main() { val result = add(3, 5) println(result) } fun add(a: Int, b: Int): Int = a + b
5
8
3
What is the primary constructor in Kotlin?
A constructor declared inside the class body.
The constructor defined within the class header.
Kotlin doesn't have constructors.
A constructor declared using the 'constructor' keyword.
Which method adds an element to a mutable list in Kotlin?
add()
put()
append()
insert()
What is the default visibility modifier for classes and members in Kotlin?
private
public
protected
internal