What is a default argument in Kotlin?
An argument that is automatically inferred by the compiler.
An argument that is required to be passed when calling the function.
An argument that is provided a default value in the function signature.
An argument that is passed to a function by reference.
Which of the following is NOT an advantage of Kotlin?
Concise syntax
More verbose than Java
Interoperable with Java
Null safety
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!
Error
Alice!
Hello,
val numbers = setOf(1, 2, 2, 3) println(numbers.size)
4
1
3
Which keyword makes a variable immutable in Kotlin?
val
final
const
let
How do you use a named argument when calling a function in Kotlin?
By using the '->' symbol followed by the argument name and value.
By specifying the argument name followed by '=' and the value inside the function call.
Named arguments are not supported in Kotlin.
By simply passing the values in the correct order.
What is a field in Kotlin?
A static variable
A property declared inside a function
A backing field for a property
A constant value
What will be printed after executing the following Kotlin code?
for (i in 1..3) { println(i * 2) }
1 2 3
246
123
2 4 6
fun main() { val numbers = listOf(1, 2, 3, 4, 5) val doubled = numbers.map { it * 2 } println(doubled) }
10
[2, 4, 6, 8, 10]
[1, 2, 3, 4, 5]
How do you specify the return type of a function in Kotlin?
By placing a colon (:) after the function parameters and specifying the type.
Kotlin infers the return type automatically; no explicit specification is needed.
Using the 'return' keyword followed by the type.
By using the '->' symbol followed by the type before the function body.