What is the output of the following Kotlin code?
fun main() { greet(name = "Alice") } fun greet(greeting: String = "Hello", name: String) { println("$greeting, $name!") }
Hello, Alice!
Alice!
Error
Hello,
What is the primary advantage of using arrays over lists in Kotlin?
Arrays are immutable.
Arrays are dynamically sized.
Arrays offer better performance for certain operations.
Arrays can store different data types.
What is the correct syntax to declare a class named 'MyClass' in Kotlin?
class MyClass()
class MyClass {}
object MyClass
public class MyClass
Which of the following is NOT a characteristic of a Kotlin List?
Provides indexed access to elements.
Can store elements of different data types.
Maintains the order of elements.
Allows duplicate elements.
Which of the following is NOT a valid way to declare an immutable list in Kotlin?
listOf<String>("apple", "banana", "cherry")
mutableListOf("apple", "banana", "cherry")
listOf("apple", "banana", "cherry")
emptyList<String>().plus("apple").plus("banana").plus("cherry")
What is the correct way to create a range of integers from 1 to 5 (inclusive) in Kotlin?
1 to 5
[1, 2, 3, 4, 5]
range(1, 5)
1..5
How do you check if a specific key exists in a Kotlin map?
containsKey()
findKey()
hasKey()
keyExists()
What is the output of the following Kotlin code: 'println(2 + 3 * 4)'?
20
10
14
Which method adds an element to the end of a mutable list in Kotlin?
append()
insert()
add()
push()
How do you access the element at index 2 in a Kotlin array named 'numbers'?
numbers.indexOf(2)
numbers.elementAt(2)
numbers[2]
numbers.get(2)