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
Greater than 10
Less than 10
What is the difference between 'val' and 'var' when declaring a property in Kotlin?
There is no difference; they are interchangeable.
'val' declares an immutable property, 'var' a mutable one.
'val' declares a mutable property, 'var' an immutable one.
'val' is for local variables, 'var' for class properties.
What is the output of the following code snippet?
val number = 5 when (number) { 1 -> println("One") 2 -> println("Two") else -> println("Other number") }
Two
Other number
One
Error
What is a data class in Kotlin?
A class that holds only constants.
A class designed to primarily hold data and provides automatically generated utility functions.
A class that cannot be instantiated.
A class for database interactions.
What is the size of the array declared in this Kotlin code?
val fruits = arrayOf("apple", "banana")
1
2
3
0
What is a default argument in Kotlin?
An argument that is passed to a function by reference.
An argument that is provided a default value in the function signature.
An argument that is required to be passed when calling the function.
An argument that is automatically inferred by the compiler.
What is the correct syntax to define a function named 'greet' that takes no arguments and returns nothing in Kotlin?
fun greet() {}
def greet() {}
function greet() {}
void greet() {}
What is the output of the following code?
for (i in 1..5) { if (i == 3) continue println(i) }
1234
12345
1245
124
What is the default visibility modifier for classes and members in Kotlin?
internal
public
protected
private
What is a lambda expression in Kotlin?
A special kind of variable.
A keyword used for error handling.
A type of loop in Kotlin.
A way to define anonymous functions.