What is the primary benefit of using polymorphism in object-oriented programming?
Flexibility and extensibility
Improved code organization
Code reusability
All of the above
Which of the following functions is NOT automatically generated for a data class in Kotlin?
toString()
copy()
equals()
run()
Which of the following is NOT a characteristic of an abstract class in Kotlin?
It cannot be instantiated.
It can have non-abstract methods with implementation.
It cannot have properties.
It can have abstract methods without implementation.
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 handle exceptions thrown in the try block.
try
To execute code regardless of whether an exception is thrown.
To specify the type of exception that the catch block can handle.
catch
What is the primary purpose of using a data class in Kotlin?
To create classes specifically for holding data and providing automatic utility functions.
To handle asynchronous operations efficiently.
To define reusable UI components.
To implement complex inheritance hierarchies.
What does the ? operator signify in Kotlin?
?
It forces a variable to throw a NullPointerException.
It's used for string interpolation.
It marks a variable as able to hold null values.
It defines a constant variable.
What is the primary difference between an abstract class and an interface in Kotlin?
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 abstract class can have constructors, while an interface cannot.
An interface can have properties, while an abstract class cannot.
Which builder function is commonly used to launch a coroutine without blocking the current thread?
runBlocking
withContext
async
launch
What is the output of the following Kotlin code?
val text = "Hello, World!" println(text.substring(7, 12))
"World"
" Worl"
Error: Index out of bounds
"World!"
What is the primary purpose of extension functions in Kotlin?
To add new functionality to existing classes without inheriting from them.
To override existing methods of a class.
To define static methods within a class.
To create abstract methods that must be implemented by subclasses.