How do you define a property in Kotlin?
Using 'var' or 'val' keyword before the variable declaration
Using 'field' keyword
Using 'property' keyword
Properties are automatically generated from constructor parameters
How do you check if a specific key exists in a Kotlin map?
findKey()
keyExists()
hasKey()
containsKey()
How do you declare a variable in Kotlin with a String value 'Hello'?
string greeting = 'Hello'
var greeting = 'Hello'
var greeting: String = "Hello"
val greeting = "Hello"
What is the correct syntax to define a function named 'greet' that takes no arguments and returns nothing in Kotlin?
function greet() {}
def greet() {}
fun greet() {}
void greet() {}
What is the difference between emptyList() and mutableListOf() in Kotlin?
emptyList()
mutableListOf()
There is no difference; both are interchangeable.
emptyList() creates an empty immutable list, while mutableListOf() creates an empty mutable list.
emptyList() creates a list with a fixed size, while mutableListOf() creates a list with dynamic size.
emptyList() is used for numbers, while mutableListOf() is used for strings.
How do you use a named argument when calling a function in Kotlin?
Named arguments are not supported in Kotlin.
By simply passing the values in the correct order.
By specifying the argument name followed by '=' and the value inside the function call.
By using the '->' symbol followed by the argument name and value.
What is the size of the array declared in this Kotlin code?
val fruits = arrayOf("apple", "banana")
1
2
3
0
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, 3}
{1, 2, 2, 3}
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) }
10
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5]
Error
What is the correct way to create a range of integers from 1 to 5 (inclusive) in Kotlin?
1 to 5
1..5
range(1, 5)