How do you define a property in Kotlin?
Using 'field' keyword
Using 'property' keyword
Properties are automatically generated from constructor parameters
Using 'var' or 'val' keyword before the variable declaration
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!")
How do you access the element at index 2 in a Kotlin array named 'numbers'?
numbers[2]
numbers.indexOf(2)
numbers.get(2)
numbers.elementAt(2)
What is the size of the array declared in this Kotlin code?
val fruits = arrayOf("apple", "banana")
3
2
0
1
What is the output of the following Kotlin code?
fun main() { greet(name = "Alice") } fun greet(greeting: String = "Hello", name: String) { println("$greeting, $name!") }
Error
Hello,
Alice!
Hello, Alice!
val numbers = setOf(1, 2, 2, 3) println(numbers.size)
4
Which of the following is NOT a valid way to declare an immutable list in Kotlin?
emptyList<String>().plus("apple").plus("banana").plus("cherry")
mutableListOf("apple", "banana", "cherry")
listOf<String>("apple", "banana", "cherry")
listOf("apple", "banana", "cherry")
fun main() { val result = add(3, 5) println(result) } fun add(a: Int, b: Int): Int = a + b
8
5
What is the correct way to create a range of integers from 1 to 5 (inclusive) in Kotlin?
[1, 2, 3, 4, 5]
1 to 5
1..5
range(1, 5)
What is the primary constructor in Kotlin?
A constructor declared inside the class body.
The constructor defined within the class header.
Kotlin doesn't have constructors.
A constructor declared using the 'constructor' keyword.