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)
[4, 8]
Error
[2, 6, 10]
[2, 4, 6, 8, 10]
Which keyword is used to declare a custom exception class in Kotlin?
try
throw
customException
exception
What is a key characteristic of a higher-order function in Kotlin?
It always throws exceptions.
It can accept functions as parameters or return a function.
It operates on primitive data types only.
It cannot be used with lambda expressions.
How do you replace all occurrences of a substring in a Kotlin String?
replaceAll()
switch()
substitute()
replace()
What annotation must be added to a method in the superclass to allow it to be overridden in a subclass?
@Abstract
@Overrideable
@Override
@Open
What is destructuring in Kotlin, particularly in the context of data classes?
Converting a data class to a different data type.
Breaking down a data class instance into its constituent properties.
Deleting specific properties from a data class instance.
Destructuring is not relevant to data classes.
How do you create a copy of a data class instance with modified properties in Kotlin?
By manually assigning each property to a new instance.
Using the clone() method.
clone()
Using the copy() method and specifying the properties to change.
copy()
Data classes are immutable and cannot be copied.
Which keyword is used to cancel an ongoing coroutine in Kotlin?
stop
terminate
interrupt
cancel
Which of the following is NOT a valid way to handle a potential NullPointerException in Kotlin?
Using the Elvis operator ?: to provide a default value if the variable is null.
?:
Performing a null check using an if statement.
if
Using the let function to execute code only if the variable is not null.
let
Using the safe call operator ?.
?.
How does a suspending function differ from a regular function in Kotlin?
Suspending functions are executed on separate threads, while regular functions run on the main thread.
Suspending functions cannot return values, while regular functions can.
Suspending functions are deprecated and should be replaced with regular functions.
Suspending functions can be paused and resumed, allowing for non-blocking asynchronous operations.