How do you exit a loop prematurely in Kotlin?
All of the above
Using the 'return' keyword
Using the 'continue' keyword
Using the 'break' keyword
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!
What is the output of the following code?
for (i in 1..5) { if (i == 3) continue println(i) }
12345
1234
1245
124
What is a field in Kotlin?
A property declared inside a function
A static variable
A backing field for a property
A constant value
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 difference between a MutableSet and an ImmutableSet in Kotlin?
MutableSets can be modified after creation, while ImmutableSets cannot.
MutableSets allow duplicate elements, while ImmutableSets do not.
There is no difference; both are interchangeable.
MutableSets are ordered, while ImmutableSets are unordered.
Which keyword is used to declare a class in Kotlin?
object
class
struct
interface
How can you check if a value is within a range in Kotlin?
Using the 'in' operator
Using the 'contains' method
None of the above
Both 'in' operator and 'contains' method can be used
How do you access the element at index 2 in a Kotlin array named 'numbers'?
numbers.indexOf(2)
numbers[2]
numbers.elementAt(2)
numbers.get(2)
Which of the following is NOT a characteristic of a Kotlin List?
Allows duplicate elements.
Maintains the order of elements.
Can store elements of different data types.
Provides indexed access to elements.