What is a default argument in Kotlin?
An argument that is required to be passed when calling the function.
An argument that is passed to a function by reference.
An argument that is automatically inferred by the compiler.
An argument that is provided a default value in the function signature.
What is the correct way to create a range of integers from 1 to 5 (inclusive) in Kotlin?
1 to 5
[1, 2, 3, 4, 5]
range(1, 5)
1..5
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}
How do you create an immutable map with key-value pairs in Kotlin?
mutableMapOf("key1" to "value1", "key2" to "value2")
hashMapOf("key1" to "value1", "key2" to "value2")
dictionaryOf("key1" to "value1", "key2" to "value2")
mapOf("key1" to "value1", "key2" to "value2")
Which loop in Kotlin guarantees that the loop body will execute at least once?
do-while loop
for loop
while loop
for-each loop
What is the output of the following Kotlin code?
fun main() { val numbers = listOf(1, 2, 3, 4, 5) val doubled = numbers.map { it * 2 } println(doubled) }
[2, 4, 6, 8, 10]
10
Error
What is the difference between a MutableSet and an ImmutableSet in Kotlin?
MutableSets allow duplicate elements, while ImmutableSets do not.
MutableSets are ordered, while ImmutableSets are unordered.
There is no difference; both are interchangeable.
MutableSets can be modified after creation, while ImmutableSets cannot.
val numbers = setOf(1, 2, 2, 3) println(numbers.size)
4
1
3
How do you define a property in Kotlin?
Using 'var' or 'val' keyword before the variable declaration
Using 'field' keyword
Properties are automatically generated from constructor parameters
Using 'property' keyword
Which data type represents a whole number in Kotlin?
Int
Float
String
Boolean