Which keyword guarantees immutability for a collection in Kotlin?
const
let
val
var
Which keyword is used to implement an interface in Kotlin?
inherits
extends
implements
uses
What happens when a coroutine encounters a suspending function?
The coroutine suspends execution at the suspending function call, allowing other work to happen on the thread.
The coroutine throws an exception because suspending functions are not allowed.
The coroutine blocks the thread until the suspending function completes its operation.
The suspending function is executed in a separate thread, running concurrently with the coroutine.
Which function is used to launch a new coroutine in Kotlin?
async
runBlocking
withContext
launch
What is the primary advantage of using coroutines in Kotlin?
Improved code readability with asynchronous operations.
Direct replacement for traditional threads.
Eliminates the need for error handling.
Reduces memory consumption by eliminating objects.
Which of the following is a valid way to define an extension function for the String class in Kotlin?
fun String.newMethod() {}
extension fun String.newMethod() {}
fun newMethod(str: String) {}
String.fun newMethod() {}
How do you throw a custom exception in Kotlin?
Custom exceptions cannot be thrown in Kotlin.
By using the try block with an instance of your custom exception class.
try
By using the throw keyword with an instance of your custom exception class.
throw
By using the catch block with an instance of your custom exception class.
catch
Which keyword is used to declare a suspending function in Kotlin?
await
coroutine
suspend
What is the output of the following Kotlin code snippet?
val numbers = listOf(1, 2, 3, 4, 5) val result = numbers.filter { it % 2 == 0 }.map { it * 2 } println(result)
[2, 6, 10]
[2, 4, 6, 8, 10]
[4, 8]
Error
What is a key characteristic of a higher-order function in Kotlin?
It can accept functions as parameters or return a function.
It operates on primitive data types only.
It cannot be used with lambda expressions.
It always throws exceptions.