Which keyword is used to declare a custom exception class in Kotlin?
exception
throw
try
customException
What is the role of a CoroutineContext?
CoroutineContext
Stores the data shared between coroutines
Provides information and settings for a coroutine
Manages the execution order of coroutines
Handles exceptions thrown within a coroutine
Which operator is used for function composition in Kotlin?
compose
.
Which function is used to launch a new coroutine in Kotlin?
runBlocking
launch
async
withContext
When is it appropriate to use the lateinit keyword in Kotlin?
lateinit
When you want to make a property nullable.
When you want to create a custom exception class.
When you want to define a constant value.
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.
Which of the following is a valid way to define an extension function for the String class in Kotlin?
String.fun newMethod() {}
extension fun String.newMethod() {}
fun newMethod(str: String) {}
fun String.newMethod() {}
What is the output of the following Kotlin code?
val text = "Hello, World!" println(text.substring(7, 12))
"World!"
Error: Index out of bounds
"World"
" Worl"
What is the primary risk associated with using the !! operator in Kotlin?
!!
It can lead to memory leaks.
It makes the code less readable.
It can lead to NullPointerExceptions if the variable is null.
It slows down the execution of the program.
What is the primary advantage of using coroutines in Kotlin?
Improved code readability with asynchronous operations.
Eliminates the need for error handling.
Reduces memory consumption by eliminating objects.
Direct replacement for traditional threads.
What is the key characteristic that distinguishes a sealed class from a regular class in Kotlin?
Sealed classes are only used for data storage.
Sealed classes cannot have constructors.
Sealed classes can only be extended within the same file.
Sealed classes cannot have abstract members.