Which of the following is NOT a valid way to handle a potential NullPointerException in Kotlin?
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.
?:
Using the safe call operator ?.
?.
How does a suspending function differ from a regular function in Kotlin?
Suspending functions can be paused and resumed, allowing for non-blocking asynchronous operations.
Suspending functions cannot return values, while regular functions can.
Suspending functions are executed on separate threads, while regular functions run on the main thread.
Suspending functions are deprecated and should be replaced with regular functions.
Which builder function is commonly used to launch a coroutine without blocking the current thread?
withContext
async
runBlocking
launch
Which operator is used for function composition in Kotlin?
.
compose
What happens when a suspending function calls another suspending function?
It creates a new thread for the nested function call
It executes the called function asynchronously using a callback
The calling function suspends until the called function completes
It throws a SuspendException
SuspendException
What is the purpose of the finally block in a Kotlin try-catch-finally statement?
finally
try-catch-finally
To define a new custom exception class.
To specify the type of exception that the catch block can handle.
catch
To execute code regardless of whether an exception is thrown.
To handle exceptions thrown in the try block.
try
How can you safely access a property of a nullable object in Kotlin?
By directly accessing the property using the dot (.) operator.
By using the non-null assertion operator !!.
!!
By using the safe call operator ?..
Nullable objects cannot have their properties accessed in Kotlin.
Which keyword is used to declare a suspending function in Kotlin?
await
coroutine
suspend
Which function is used to launch a new coroutine in Kotlin?
Which of the following is a valid way to define an extension function for the String class in Kotlin?
fun newMethod(str: String) {}
fun String.newMethod() {}
String.fun newMethod() {}
extension fun String.newMethod() {}