Which Kotlin function is used to combine elements of two collections into pairs?
combine()
pair()
merge()
zip()
Which keyword is used to implement an interface in Kotlin?
inherits
uses
implements
extends
When using sealed classes in Kotlin, where must the subclasses be defined?
Anywhere within the same module.
Within the same file as the sealed class declaration.
Subclasses can be defined in Java, but not in Kotlin.
In a separate file specifically designated for subclasses.
What role does a CoroutineScope play in managing coroutines?
CoroutineScope
Defines the lifetime of a group of coroutines.
Handles exceptions thrown within threads.
Converts blocking code to asynchronous operations.
Executes suspending functions synchronously.
When is it appropriate to use the lateinit keyword in Kotlin?
lateinit
When you want to make a property nullable.
When you want to initialize a non-nullable property later in the code, typically when you are certain it will be assigned a non-null value before its first use.
When you want to create a custom exception class.
When you want to define a constant value.
What is the primary purpose of using a data class in Kotlin?
To handle asynchronous operations efficiently.
To implement complex inheritance hierarchies.
To define reusable UI components.
To create classes specifically for holding data and providing automatic utility functions.
How do type-safe builders contribute to code correctness?
By optimizing the performance of code that manipulates large datasets.
By preventing invalid states from being represented in the code.
By enabling dynamic code execution at runtime.
By automatically generating unit tests for complex structures.
What is a potential downside of relying heavily on recursion in Kotlin?
It is not supported for complex data structures like trees and graphs.
It can make the code more difficult to debug and understand compared to iterative solutions.
It always leads to slower performance than iterative approaches.
It prevents the use of higher-order functions like 'map' and 'filter'.
What is the difference between any() and all() functions for collections?
any()
all()
any() checks if all elements match a condition, while all() checks if at least one element matches.
any() checks if at least one element matches a condition, while all() checks if all elements match.
any() returns the first matching element, while all() returns a list of all matching elements.
any() and all() are interchangeable and produce the same result.
What benefit do sealed classes provide when used with when expressions in Kotlin?
when
Sealed classes do not offer any specific benefits with when expressions.
Enhanced performance for pattern matching.
Improved code readability.
The ability to omit the else branch in certain scenarios.
else