Which data structure is best suited for storing a collection of unique elements in Kotlin?
List
Array
Map
Set
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,
Hello, Alice!
Error
Alice!
How do you check if a specific key exists in a Kotlin map?
findKey()
hasKey()
keyExists()
containsKey()
How do you define a property in Kotlin?
Using 'property' keyword
Properties are automatically generated from constructor parameters
Using 'var' or 'val' keyword before the variable declaration
Using 'field' keyword
How do you define a function in Kotlin?
void myFunction() {}
function myFunction() {}
def myFunction() {}
fun myFunction() {}
How do you pass a lambda expression as an argument to a function in Kotlin?
By using the 'function' keyword before the lambda expression.
Lambda expressions cannot be passed as arguments in Kotlin.
By enclosing the lambda expression in parentheses.
By simply passing the lambda expression without any special syntax.
fun main() { val result = add(3, 5) println(result) } fun add(a: Int, b: Int): Int = a + b
8
3
5
What is a default argument in Kotlin?
An argument that is provided a default value in the function signature.
An argument that is passed to a function by reference.
An argument that is required to be passed when calling the function.
An argument that is automatically inferred by the compiler.
What is the difference between 'val' and 'var' when declaring a property in Kotlin?
'val' declares a mutable property, 'var' an immutable one.
There is no difference; they are interchangeable.
'val' is for local variables, 'var' for class properties.
'val' declares an immutable property, 'var' a mutable one.
What is the correct way to print 'Hello, World!' to the console in Kotlin?
System.out.println("Hello, World!")
console.log("Hello, World!")
print("Hello, World!")
println("Hello, World!")