How do you access the value associated with the key "name" in a Kotlin map named user?
user
user.name
user.get("name")
user.getValue("name")
user["name"]
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.
Which keyword makes a variable immutable in Kotlin?
let
val
const
final
How can you check if a value is within a range in Kotlin?
Both 'in' operator and 'contains' method can be used
None of the above
Using the 'contains' method
Using the 'in' operator
How do you declare a variable in Kotlin with a String value 'Hello'?
val greeting = "Hello"
string greeting = 'Hello'
var greeting: String = "Hello"
var greeting = 'Hello'
What is the output of the following Kotlin code snippet?
val x = 5 if (x > 10) { println("Greater than 10") } else if (x < 10) { println("Less than 10") } else { println("Equal to 10") }
Equal to 10
The code will not compile
Greater than 10
Less than 10
What is the purpose of the 'when' statement in Kotlin?
To declare a variable
To define a function
To perform different actions based on different conditions
To execute a block of code repeatedly
How do you define a property in Kotlin?
Using 'property' keyword
Using 'field' keyword
Using 'var' or 'val' keyword before the variable declaration
Properties are automatically generated from constructor parameters
Which loop in Kotlin guarantees that the loop body will execute at least once?
while loop
do-while loop
for-each loop
for 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]
Error
10
[1, 2, 3, 4, 5]