How do you exit a loop prematurely in Kotlin?
Using the 'return' keyword
Using the 'continue' keyword
Using the 'break' keyword
All of the above
What is the size of the array declared in this Kotlin code?
val fruits = arrayOf("apple", "banana")
2
1
0
3
What is the difference between a MutableSet and an ImmutableSet in Kotlin?
There is no difference; both are interchangeable.
MutableSets allow duplicate elements, while ImmutableSets do not.
MutableSets are ordered, while ImmutableSets are unordered.
MutableSets can be modified after creation, while ImmutableSets cannot.
What is the primary advantage of using arrays over lists in Kotlin?
Arrays are dynamically sized.
Arrays offer better performance for certain operations.
Arrays are immutable.
Arrays can store different data types.
How do you pass a lambda expression as an argument to a function in Kotlin?
By using the 'function' keyword before the lambda expression.
By enclosing the lambda expression in parentheses.
Lambda expressions cannot be passed as arguments in Kotlin.
By simply passing the lambda expression without any special syntax.
Which loop in Kotlin guarantees that the loop body will execute at least once?
while loop
for-each loop
do-while loop
for loop
How do you define a property in Kotlin?
Properties are automatically generated from constructor parameters
Using 'field' keyword
Using 'property' keyword
Using 'var' or 'val' keyword before the variable declaration
How do you create an instance of a class named 'MyClass' in Kotlin?
var myClass = new MyClass()
val myClass = MyClass()
MyClass myClass = new MyClass()
MyClass myClass
What is the correct syntax to define a function named 'greet' that takes no arguments and returns nothing in Kotlin?
void greet() {}
fun greet() {}
function greet() {}
def greet() {}
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!
Error
Hello,
Hello, Alice!