What does the ? operator signify in Kotlin?
?
It's used for string interpolation.
It defines a constant variable.
It forces a variable to throw a NullPointerException.
It marks a variable as able to hold null values.
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 handle exceptions thrown in the try block.
try
To execute code regardless of whether an exception is thrown.
How do type-safe builders contribute to code correctness?
By preventing invalid states from being represented in the code.
By optimizing the performance of code that manipulates large datasets.
By automatically generating unit tests for complex structures.
By enabling dynamic code execution at runtime.
When is it appropriate to use the lateinit keyword in Kotlin?
lateinit
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.
When you want to make a property nullable.
What is the purpose of the StringBuilder class in Kotlin?
StringBuilder
To convert between different string encodings.
To create immutable strings.
To efficiently build mutable strings.
To perform regular expression matching.
What annotation must be added to a method in the superclass to allow it to be overridden in a subclass?
@Open
@Abstract
@Overrideable
@Override
How can you find the first element in a list that satisfies a given condition?
filter().first()
first()
search()
find()
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 prevents the function from returning any value.
It forces the use of tail recursion optimization.
How do you throw a custom exception in Kotlin?
Custom exceptions cannot be thrown in Kotlin.
By using the catch block with an instance of your custom exception class.
By using the throw keyword with an instance of your custom exception class.
throw
By using the try block with an instance of your custom exception class.
What is the primary advantage of using coroutines in Kotlin?
Improved code readability with asynchronous operations.
Direct replacement for traditional threads.
Eliminates the need for error handling.
Reduces memory consumption by eliminating objects.