What is the output of the following Kotlin code?
val text = "Hello, World!" println(text.substring(7, 12))
" Worl"
Error: Index out of bounds
"World"
"World!"
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
Using the Elvis operator ?: to provide a default value if the variable is null.
?:
Using the safe call operator ?.
?.
Performing a null check using an if statement.
if
How does a suspending function differ from a regular function in Kotlin?
Suspending functions are deprecated and should be replaced with regular functions.
Suspending functions can be paused and resumed, allowing for non-blocking asynchronous operations.
Suspending functions are executed on separate threads, while regular functions run on the main thread.
Suspending functions cannot return values, while regular functions can.
What happens when a coroutine encounters a suspending function?
The coroutine blocks the thread until the suspending function completes its operation.
The suspending function is executed in a separate thread, running concurrently with the coroutine.
The coroutine throws an exception because suspending functions are not allowed.
The coroutine suspends execution at the suspending function call, allowing other work to happen on the thread.
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.
Which of the following is NOT a characteristic of an abstract class in Kotlin?
It cannot have properties.
It can have non-abstract methods with implementation.
It cannot be instantiated.
It can have abstract methods without implementation.
Which of the following is NOT a standard coroutine scope in Kotlin?
GlobalScope
viewModelScope
CoroutineScope
lifecycleScope
How can you find the first element in a list that satisfies a given condition?
first()
find()
search()
filter().first()
How do you define a suspending function in Kotlin?
By implementing the Suspendable interface
Suspendable
By annotating the function with @Coroutine
@Coroutine
By extending the CoroutineScope interface
By using the suspend keyword in the function definition
suspend
What happens if you try to access a lateinit property before it has been initialized?
lateinit
An UninitializedPropertyAccessException is thrown.
A NullPointerException is thrown.
A KotlinNullPointerException is thrown.
An IllegalArgumentException is thrown.