How do you throw a custom exception in Kotlin?
By using the throw keyword with an instance of your custom exception class.
throw
By using the catch block with an instance of your custom exception class.
catch
Custom exceptions cannot be thrown in Kotlin.
By using the try block with an instance of your custom exception class.
try
What is the purpose of the StringBuilder class in Kotlin?
StringBuilder
To perform regular expression matching.
To efficiently build mutable strings.
To create immutable strings.
To convert between different string encodings.
What does the ? operator signify in Kotlin?
?
It defines a constant variable.
It marks a variable as able to hold null values.
It's used for string interpolation.
It forces a variable to throw a NullPointerException.
What is a potential risk of using recursion without a proper base case?
It forces the use of tail recursion optimization.
It can lead to an infinite loop and a StackOverflowError.
It prevents the function from returning any value.
It makes the code less readable and harder to understand.
When is it appropriate to use the lateinit keyword in Kotlin?
lateinit
When you want to define a constant value.
When you want to make a property nullable.
When you want to create a custom exception class.
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.
What is the primary benefit of using polymorphism in object-oriented programming?
Code reusability
Improved code organization
Flexibility and extensibility
All of the above
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 cannot have abstract members.
Sealed classes can only be extended within the same file.
Which builder function is commonly used to launch a coroutine without blocking the current thread?
async
withContext
launch
runBlocking
Which keyword is used to declare a suspending function in Kotlin?
await
suspend
coroutine
Which Kotlin function is used to combine elements of two collections into pairs?
combine()
zip()
merge()
pair()