How do you access the value associated with the key "name" in a Kotlin map named user?
user
user.get("name")
user.getValue("name")
user.name
user["name"]
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!
Hello,
Error
Alice!
How can you add an element to a mutable list in Kotlin?
Using the push() function
push()
Using the add() function
add()
You cannot add elements to a mutable list once it's created.
Using the append() function
append()
Which of the following is NOT a characteristic of a Kotlin List?
Provides indexed access to elements.
Allows duplicate elements.
Maintains the order of elements.
Can store elements of different data types.
What is the output of the following Kotlin code: 'println(2 + 3 * 4)'?
14
20
10
Which keyword is used to declare a class in Kotlin?
struct
object
interface
class
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.
Using the 'secondary' keyword before the constructor declaration.
By defining another constructor inside the class body using the 'constructor' keyword.
What is the output of listOf(1, 2, 2, 3).toSet() in Kotlin?
listOf(1, 2, 2, 3).toSet()
{1, 2, 2, 3}
[1, 2, 2, 3]
{1, 2, 3}
[1, 2, 3]
What is the primary advantage of using arrays over lists in Kotlin?
Arrays offer better performance for certain operations.
Arrays can store different data types.
Arrays are immutable.
Arrays are dynamically sized.
What is the correct way to print 'Hello, World!' to the console in Kotlin?
println("Hello, World!")
console.log("Hello, World!")
print("Hello, World!")
System.out.println("Hello, World!")