How do you exit a loop prematurely in Kotlin?
Using the 'break' keyword
Using the 'continue' keyword
Using the 'return' keyword
All of the above
What is the output of the following Kotlin code?
fun main() { greet(name = "Alice") } fun greet(greeting: String = "Hello", name: String) { println("$greeting, $name!") }
Alice!
Hello,
Hello, Alice!
Error
Which of the following is NOT an advantage of Kotlin?
Concise syntax
More verbose than Java
Interoperable with Java
Null safety
How do you pass a lambda expression as an argument to a function in Kotlin?
By simply passing the lambda expression without any special syntax.
Lambda expressions cannot be passed as arguments in Kotlin.
By enclosing the lambda expression in parentheses.
By using the 'function' keyword before the lambda expression.
What is the primary difference between listOf() and mutableListOf() in Kotlin?
listOf()
mutableListOf()
listOf() creates a fixed-size list, while mutableListOf() creates a dynamically sized list.
listOf() creates an immutable list, while mutableListOf() creates a mutable list.
listOf() creates a list of integers, while mutableListOf() creates a list of strings.
There is no difference; both functions are interchangeable.
What is the most appropriate collection type in Kotlin to store a list of unique user IDs?
Set
MutableList
Map
List
Which data structure is best suited for storing a collection of unique elements in Kotlin?
Array
How do you call a method named 'myMethod' on an object 'myObject' in Kotlin?
myObject.myMethod()
myMethod(myObject)
myObject->myMethod()
call(myObject, myMethod)
What is the correct syntax to define a function named 'greet' that takes no arguments and returns nothing in Kotlin?
void greet() {}
function greet() {}
def greet() {}
fun greet() {}
Which code snippet creates an immutable list of strings in Kotlin?
val names = arrayListOf("Alice", "Bob", "Charlie")
val names = setOf("Alice", "Bob", "Charlie")
val names = mutableListOf("Alice", "Bob", "Charlie")
val names = listOf("Alice", "Bob", "Charlie")