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
[1, 2, 3, 4, 5]
Error
How do you create an immutable map with key-value pairs in Kotlin?
mapOf("key1" to "value1", "key2" to "value2")
hashMapOf("key1" to "value1", "key2" to "value2")
mutableMapOf("key1" to "value1", "key2" to "value2")
dictionaryOf("key1" to "value1", "key2" to "value2")
Which method adds an element to the end of a mutable list in Kotlin?
push()
add()
insert()
append()
How do you access the element at index 2 in a Kotlin array named 'numbers'?
numbers.indexOf(2)
numbers.elementAt(2)
numbers.get(2)
numbers[2]
What is the output of the following code?
for (i in 1..5) { if (i == 3) continue println(i) }
1234
124
1245
12345
How do you define a secondary constructor in Kotlin?
By using the 'override' keyword before the constructor declaration.
Using the 'secondary' keyword before the constructor declaration.
You can't define multiple constructors in Kotlin.
By defining another constructor inside the class body using the 'constructor' keyword.
What is the correct syntax to declare a class named 'MyClass' in Kotlin?
public class MyClass
object MyClass
class MyClass {}
class MyClass()
What is the default visibility modifier for classes and members in Kotlin?
internal
private
public
protected
How do you define a function in Kotlin?
fun myFunction() {}
void myFunction() {}
def myFunction() {}
function myFunction() {}
What is the output of the following Kotlin code: 'println(2 + 3 * 4)'?
20
14