What is the output of the following Kotlin code?
val numbers = setOf(1, 2, 2, 3) println(numbers.size)
1
3
4
Error
How do you use a named argument when calling a function in Kotlin?
By specifying the argument name followed by '=' and the value inside the function call.
Named arguments are not supported in Kotlin.
By using the '->' symbol followed by the argument name and value.
By simply passing the values in the correct order.
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!")
fun main() { val result = add(3, 5) println(result) } fun add(a: Int, b: Int): Int = a + b
8
5
How can you add an element to a mutable list in Kotlin?
You cannot add elements to a mutable list once it's created.
Using the append() function
append()
Using the push() function
push()
Using the add() function
add()
How do you define a property in Kotlin?
Properties are automatically generated from constructor parameters
Using 'property' keyword
Using 'field' keyword
Using 'var' or 'val' keyword before the variable declaration
How do you define a function in Kotlin?
function myFunction() {}
def myFunction() {}
fun myFunction() {}
void myFunction() {}
How do you specify the return type of a function in Kotlin?
By placing a colon (:) after the function parameters and specifying the type.
By using the '->' symbol followed by the type before the function body.
Kotlin infers the return type automatically; no explicit specification is needed.
Using the 'return' keyword followed by the type.
Which of the following is NOT a valid way to declare an immutable list in Kotlin?
mutableListOf("apple", "banana", "cherry")
emptyList<String>().plus("apple").plus("banana").plus("cherry")
listOf<String>("apple", "banana", "cherry")
listOf("apple", "banana", "cherry")
What is the primary constructor in Kotlin?
The constructor defined within the class header.
Kotlin doesn't have constructors.
A constructor declared using the 'constructor' keyword.
A constructor declared inside the class body.