What is the correct syntax to define a function named 'greet' that takes no arguments and returns nothing in Kotlin?
fun greet() {}
def greet() {}
void greet() {}
function greet() {}
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.
Which of the following is NOT a characteristic of a Kotlin List?
Provides indexed access to elements.
Allows duplicate elements.
Can store elements of different data types.
Maintains the order of elements.
Which method adds an element to a mutable list in Kotlin?
add()
insert()
put()
append()
Which keyword is used to declare a class in Kotlin?
class
object
interface
struct
What happens when you try to access a non-existent key in a Kotlin map?
It returns a default value.
It throws a NullPointerException.
It throws an IndexOutOfBoundsException.
It returns null.
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
Greater than 10
The code will not compile
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 a mutable property, 'var' an immutable one.
'val' is for local variables, 'var' for class properties.
'val' declares an immutable property, 'var' a mutable one.
What is the output of the following Kotlin code: 'println(2 + 3 * 4)'?
Error
14
20
10
Can you modify the elements of an immutable list in Kotlin?
Yes
No