Which of the following is NOT a benefit of immutability in functional programming?
Increased code complexity.
Improved code readability.
Reduced risk of side effects.
Easier to reason about program state.
What is a higher-order function in Kotlin?
A function that takes another function as a parameter or returns a function.
A function that is declared using the inline keyword.
inline
A function that operates on collections and sequences.
A function that cannot be overridden in a subclass.
What is a potential risk of using recursion without a proper base case?
It can lead to an infinite loop and a StackOverflowError.
It forces the use of tail recursion optimization.
It makes the code less readable and harder to understand.
It prevents the function from returning any value.
What happens when a suspending function calls another suspending function?
The calling function suspends until the called function completes
It creates a new thread for the nested function call
It throws a SuspendException
SuspendException
It executes the called function asynchronously using a callback
What is the key characteristic that distinguishes a sealed class from a regular class in Kotlin?
Sealed classes cannot have abstract members.
Sealed classes can only be extended within the same file.
Sealed classes are only used for data storage.
Sealed classes cannot have constructors.
What is a key characteristic of a higher-order function in Kotlin?
It operates on primitive data types only.
It can accept functions as parameters or return a function.
It cannot be used with lambda expressions.
It always throws exceptions.
What is the primary risk associated with using the !! operator in Kotlin?
!!
It makes the code less readable.
It slows down the execution of the program.
It can lead to memory leaks.
It can lead to NullPointerExceptions if the variable is null.
What is the purpose of the CoroutineContext?
CoroutineContext
Synchronizes access to shared resources.
Serializes data passed between coroutines.
Stores information about the coroutine's execution environment.
Defines the entry point for a coroutine.
When might it be more appropriate to choose an iterative approach over recursion in Kotlin?
When the problem can be solved more efficiently with loops, especially for large inputs.
When the function needs to be inlined for performance optimization.
When the recursive solution would be significantly more readable and concise.
When the problem involves manipulating immutable data structures.
How do you create a copy of a data class instance with modified properties in Kotlin?
Using the clone() method.
clone()
Using the copy() method and specifying the properties to change.
copy()
Data classes are immutable and cannot be copied.
By manually assigning each property to a new instance.