What is a potential risk of using recursion without a proper base case?
It can lead to an infinite loop and a StackOverflowError.
It makes the code less readable and harder to understand.
It forces the use of tail recursion optimization.
It prevents the function from returning any value.
Which of the following is a valid way to define an extension function for the String class in Kotlin?
extension fun String.newMethod() {}
fun String.newMethod() {}
String.fun newMethod() {}
fun newMethod(str: String) {}
What is the primary benefit of using polymorphism in object-oriented programming?
Improved code organization
All of the above
Flexibility and extensibility
Code reusability
What is the purpose of runBlocking in Kotlin coroutines?
runBlocking
To switch between different dispatchers
To define a custom coroutine scope
To execute a suspending function from a non-suspending context
To cancel an ongoing coroutine
What happens if you try to access a lateinit property before it has been initialized?
lateinit
An IllegalArgumentException is thrown.
A NullPointerException is thrown.
A KotlinNullPointerException is thrown.
An UninitializedPropertyAccessException is thrown.
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.
The ability to omit the else branch in certain scenarios.
else
Improved code readability.
Enhanced performance for pattern matching.
What is destructuring in Kotlin, particularly in the context of data classes?
Deleting specific properties from a data class instance.
Breaking down a data class instance into its constituent properties.
Converting a data class to a different data type.
Destructuring is not relevant to data classes.
Can a sealed class be instantiated directly in Kotlin?
Yes, but only inside the same file where it's defined.
Only if the sealed class is declared as open.
open
No, sealed classes cannot be instantiated directly.
Yes, just like regular classes.
Which builder function is commonly used to launch a coroutine without blocking the current thread?
async
withContext
launch
What is the primary difference between an abstract class and an interface in Kotlin?
An abstract class can have constructors, while an interface cannot.
There is no difference; they are interchangeable.
An abstract class can only inherit from one other class, while an interface can inherit from multiple.
An interface can have properties, while an abstract class cannot.