How do you define a property in Kotlin?
Using 'field' keyword
Properties are automatically generated from constructor parameters
Using 'property' keyword
Using 'var' or 'val' keyword before the variable declaration
What is the correct syntax to define a function named 'greet' that takes no arguments and returns nothing in Kotlin?
def greet() {}
fun greet() {}
function greet() {}
void greet() {}
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
Which of the following is NOT a valid way to declare an immutable list in Kotlin?
listOf("apple", "banana", "cherry")
listOf<String>("apple", "banana", "cherry")
emptyList<String>().plus("apple").plus("banana").plus("cherry")
mutableListOf("apple", "banana", "cherry")
What is the primary advantage of using arrays over lists in Kotlin?
Arrays are dynamically sized.
Arrays can store different data types.
Arrays offer better performance for certain operations.
Arrays are immutable.
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") }
The code will not compile
Equal to 10
Less than 10
Greater than 10
How do you define a secondary constructor in Kotlin?
By using the 'override' 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.
Using the 'secondary' keyword before the constructor declaration.
What is the difference between emptyList() and mutableListOf() in Kotlin?
emptyList()
mutableListOf()
emptyList() creates a list with a fixed size, while mutableListOf() creates a list with dynamic size.
There is no difference; both are interchangeable.
emptyList() creates an empty immutable list, while mutableListOf() creates an empty mutable list.
emptyList() is used for numbers, while mutableListOf() is used for strings.
Which data type represents a whole number in Kotlin?
Boolean
Int
Float
String
What is the primary difference between listOf() and mutableListOf() in Kotlin?
listOf()
listOf() creates an immutable list, while mutableListOf() creates a mutable list.
There is no difference; both functions are interchangeable.
listOf() creates a list of integers, while mutableListOf() creates a list of strings.
listOf() creates a fixed-size list, while mutableListOf() creates a dynamically sized list.