Search Tutorials


Kotlin MCQ Questions and Answers | JavaInUse

Kotlin MCQ Questions and Answers

Q. What is the difference between val and var in Kotlin?

A. val is final, var is not final
B. 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 time
B. 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 members
B. 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 statements
B. 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 function
B. 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 val
B. 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 programming
B. 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 members
B. 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 class
B. To declare anonymous objects
C. To create object expressions
D. All of the above





Q. What is a sealed class in Kotlin?

A. A class that can't be inherited
B. A class with restricted subclassing to the same file
C. A class used for representing restricted hierarchies
D. Both B and C

Q. What are higher-order functions in Kotlin?

A. Functions that take functions as parameters
B. Functions that return other functions
C. Functions that can be stored in variables
D. All of the above

Q. What is the purpose of infix notation in Kotlin?

A. To call functions without using dot and parentheses
B. To create operator overloading
C. To make code more readable for certain functions
D. Both A and C

Q. What is the scope function 'apply' used for in Kotlin?

A. To configure properties of an object
B. To execute a block of code on an object
C. Returns the object itself after applying operations
D. All of the above

Q. What is the difference between List and MutableList in Kotlin?

A. List is read-only, MutableList can be modified
B. List is immutable, MutableList is mutable
C. MutableList provides add() and remove() operations
D. All of the above

Q. What is a backing field in Kotlin?

A. A field automatically generated for properties that need it
B. A field used in custom getter/setter implementations
C. A field referenced using the 'field' identifier
D. All of the above

Q. What is the purpose of the 'by' keyword in Kotlin?

A. To implement delegation pattern
B. To delegate property initialization
C. To implement interfaces by delegation
D. All of the above

Q. What is a typeAlias in Kotlin?

A. A way to give alternative names to existing types
B. A way to create custom types
C. Used to simplify complex type declarations
D. Both A and C

Q. What is the purpose of the 'suspend' keyword in Kotlin?

A. To mark a function as coroutine-compatible
B. To indicate that a function can be paused and resumed
C. To enable asynchronous programming
D. All of the above

Q. What are reified type parameters in Kotlin?

A. Type parameters that are accessible at runtime
B. Used with inline functions only
C. Allow type checking of generic parameters
D. All of the above

Q. What is the difference between 'let' and 'run' scope functions?

A. 'let' uses 'it' as context object, 'run' uses 'this'
B. 'let' is used for null safety checks, 'run' for object configuration
C. 'let' returns the lambda result, 'run' returns the context object
D. Both A and B

Q. What are destructuring declarations in Kotlin?

A. A way to break down objects into multiple variables
B. Used with data classes and collections
C. Requires componentN() functions
D. All of the above

Q. What is the purpose of 'crossinline' modifier in Kotlin?

A. To prevent non-local returns in lambdas
B. Used with inline functions
C. To ensure lambda can be executed in another context
D. All of the above

Q. What is the purpose of 'const' modifier in Kotlin?

A. To declare compile-time constants
B. Can only be used with primitive types and String
C. Must be declared at top-level or in objects
D. All of the above