How do you access the value associated with the key "name" in a Kotlin map named user?
user
user.name
user.getValue("name")
user["name"]
user.get("name")
What is the purpose of single-line comments in Kotlin?
To define code blocks
To declare variables
To add explanations or disable code temporarily
To import external libraries
What is the correct way to print 'Hello, World!' to the console in Kotlin?
println("Hello, World!")
print("Hello, World!")
console.log("Hello, World!")
System.out.println("Hello, World!")
Which loop in Kotlin guarantees that the loop body will execute at least once?
for-each loop
for loop
do-while loop
while loop
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 returns null.
It throws an IndexOutOfBoundsException.
How can you check if a value is within a range in Kotlin?
None of the above
Using the 'contains' method
Both 'in' operator and 'contains' method can be used
Using the 'in' operator
How do you define a property in Kotlin?
Properties are automatically generated from constructor parameters
Using 'field' keyword
Using 'property' keyword
Using 'var' or 'val' keyword before the variable declaration
What is the output of the following Kotlin code?
fun main() { greet(name = "Alice") } fun greet(greeting: String = "Hello", name: String) { println("$greeting, $name!") }
Alice!
Hello,
Error
Hello, Alice!
How do you declare a variable in Kotlin with a String value 'Hello'?
var greeting: String = "Hello"
var greeting = 'Hello'
string greeting = 'Hello'
val greeting = "Hello"
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.