Which of the following is NOT a standard coroutine scope in Kotlin?
CoroutineScope
viewModelScope
GlobalScope
lifecycleScope
What is the difference between any() and all() functions for collections?
any()
all()
any() checks if at least one element matches a condition, while all() checks if all elements match.
any() checks if all elements match a condition, while all() checks if at least one element matches.
any() and all() are interchangeable and produce the same result.
any() returns the first matching element, while all() returns a list of all matching elements.
How can you safely access a property of a nullable object in Kotlin?
By using the safe call operator ?..
?.
By directly accessing the property using the dot (.) operator.
.
Nullable objects cannot have their properties accessed in Kotlin.
By using the non-null assertion operator !!.
!!
What is the purpose of the finally block in a Kotlin try-catch-finally statement?
finally
try-catch-finally
To execute code regardless of whether an exception is thrown.
To define a new custom exception class.
To handle exceptions thrown in the try block.
try
To specify the type of exception that the catch block can handle.
catch
What benefit do sealed classes provide when used with when expressions in Kotlin?
when
Improved code readability.
The ability to omit the else branch in certain scenarios.
else
Enhanced performance for pattern matching.
Sealed classes do not offer any specific benefits with when expressions.
In Kotlin, what keyword is used to mark a class as inheritable?
extends
inherit
derivable
open
Which of the following is NOT a valid way to handle a potential NullPointerException in Kotlin?
Using the safe call operator ?.
Using the let function to execute code only if the variable is not null.
let
Performing a null check using an if statement.
if
Using the Elvis operator ?: to provide a default value if the variable is null.
?:
Which function type represents a function that takes an Int and returns a String?
Int.() -> String
String(Int)
(Int) -> Unit
(Int) -> String
How does the 'inline' keyword optimize function calls in Kotlin?
It replaces the function call with its actual code at compile time.
It creates a separate thread for the function execution.
It disables null safety checks within the function.
It converts the function into a lambda expression automatically.
Which keyword is used to implement an interface in Kotlin?
uses
inherits
implements