Kotlin MCQ Questions and Answers
Q. What is the difference between val and var in Kotlin?
A. val is final, var is not finalB. val is immutable, var is mutable
C. val can only be assigned once, var can be reassigned
D. All of the above
Q. What is a Null Safety feature in Kotlin?
A. It prevents null pointer exceptions at compile timeB. It allows nullable types with ? operator
C. It provides safe call operator (?.) and Elvis operator (?:)
D. All of the above
Q. What is a data class in Kotlin?
A. A class that only contains data membersB. A class that automatically generates equals(), hashCode(), toString(), and copy() methods
C. A class marked with 'data' keyword
D. Both B and C
Q. What is the purpose of 'when' expression in Kotlin?
A. It's a replacement for switch-case statementsB. It can be used as an expression returning a value
C. It supports multiple value checks and type checks
D. All of the above
Q. What is an Extension Function in Kotlin?
A. A function that extends another functionB. A function that adds new functionality to an existing class without inheriting from it
C. A function inside an interface
D. A function that extends the main function
Q. What is the difference between lateinit and lazy initialization in Kotlin?
A. lateinit can only be used with var, while lazy is used with valB. lazy initializes the variable on first access, lateinit requires manual initialization
C. lateinit doesn't require null checks, lazy handles null safety automatically
D. All of the above
Q. What are Coroutines in Kotlin?
A. A design pattern for concurrent programmingB. Lightweight threads for asynchronous programming
C. A way to write asynchronous code sequentially
D. Both B and C
Q. What is a companion object in Kotlin?
A. A replacement for Java's static membersB. An object declaration inside a class
C. Can implement interfaces and hold constants
D. All of the above
Q. What is the purpose of the 'object' keyword in Kotlin?
A. To create a singleton classB. To declare anonymous objects
C. To create object expressions
D. All of the above