Which company created Kotlin?
- A. Google
- B. Oracle
- C. Microsoft
- D. JetBrains (correct)
Which keyword declares a read-only variable in Kotlin?
- A. var
- B. val (correct)
- C. const only
- D. let
Which keyword declares a variable that can be reassigned in Kotlin?
- A. val
- B. let
- C. var (correct)
- D. mut
Which keyword declares a function in Kotlin?
- A. fun (correct)
- B. function
- C. func
- D. def
What is the entry point of a Kotlin program?
- A. start()
- B. static void main()
- C. fun main() (correct)
- D. def main()
Which function prints a line to the console in Kotlin?
- A. System.print()
- B. println() (correct)
- C. echo()
- D. console.log()
What file extension do Kotlin source files use?
- A. .kt (correct)
- B. .kts only
- C. .kotlin
- D. .ko
Is a semicolon required at the end of each Kotlin statement?
- A. Only inside functions
- B. Yes, always
- C. No, it is optional (correct)
- D. Only after return
Which syntax inserts a variable into a Kotlin string?
- A. "Hello %name"
- B. "Hello {name}"
- C. "Hello $name" (correct)
- D. "Hello #name"
Which type holds whole numbers by default in Kotlin?
- A. Integer
- B. Long only
- C. Number
- D. Int (correct)
Which type is used for true/false values in Kotlin?
- A. Bit
- B. Bool
- C. Logic
- D. Boolean (correct)
Which keyword replaces the switch statement in Kotlin?
- A. match
- B. select
- C. case
- D. when (correct)
What does 1..5 create in Kotlin?
- A. A range from 1 to 5 inclusive (correct)
- B. A range from 1 to 4
- C. A list of two numbers
- D. A decimal number
Which function creates a read-only list in Kotlin?
- A. listOf() (correct)
- B. arrayListOf only
- C. newList()
- D. List()
Which function creates a mutable list in Kotlin?
- A. mutableListOf() (correct)
- B. fixedListOf()
- C. readOnlyList()
- D. listOf()
Kotlin is the officially preferred language for which platform?
- A. iOS
- B. PlayStation
- C. Android (correct)
- D. Windows desktop
Which keyword is used for a class whose main job is holding data?
- A. struct
- B. data class (correct)
- C. record
- D. bean
How do you write a single-line comment in Kotlin?
- A. -- comment
- B. # comment
- C. ; comment
- D. // comment (correct)
What does if return in Kotlin when used as an expression?
- A. Always a Boolean
- B. A value (correct)
- C. Nothing, it is only a statement
- D. Always Unit
Which keyword is used for a for loop over a range in Kotlin?
- A. for (i in 1..3) (correct)
- B. for (i = 1; i <= 3; i++)
- C. foreach i in 1..3
- D. loop i to 3
What does the ? in String? mean?
- A. The variable is optional to declare
- B. The variable can hold null (correct)
- C. The type is unknown
- D. The string is empty
What does the safe-call operator ?. do?
- A. Calls the member only if the value is not null, otherwise returns null (correct)
- B. Throws if the value is null
- C. Converts null to an empty string
- D. Checks the type
What does the Elvis operator ?: do?
- A. Casts a value
- B. Compares two values
- C. Creates a range
- D. Returns the right side when the left side is null (correct)
What does the !! operator do?
- A. Asserts the value is not null and throws if it is (correct)
- B. Negates a Boolean twice
- C. Makes a value nullable
- D. Checks equality
Which methods does a data class generate automatically?
- A. main()
- B. Only getters
- C. Only toString()
- D. equals(), hashCode(), toString() and copy() (correct)
Are classes in Kotlin open for inheritance by default?
- A. No, they are final unless marked open (correct)
- B. Only abstract classes
- C. Yes, always
- D. Only data classes
Which keyword lets a class be inherited from?
- A. open (correct)
- B. virtual
- C. extends
- D. public
What does the object keyword declare?
- A. An enum
- B. A singleton (correct)
- C. A data class
- D. An abstract class
What is a companion object used for?
- A. Members tied to the class rather than an instance, like static members (correct)
- B. Holding private constructors
- C. Creating copies of an object
- D. Declaring interfaces
What does a lambda like { x: Int -> x * 2 } represent?
- A. A function value (correct)
- B. A range
- C. A class body
- D. A map entry
In a single-parameter lambda, what is the implicit name of the parameter?
- A. this
- B. self
- C. arg
- D. it (correct)
What does list.filter { it > 2 } return?
- A. The count of elements greater than 2
- B. A new list with elements greater than 2 (correct)
- C. True or false
- D. The first element greater than 2
What does list.map { it * 2 } return?
- A. A map of keys to values
- B. A new list with each element doubled (correct)
- C. The sum of all elements times 2
- D. The original list doubled in size
What is an extension function?
- A. A function that takes unlimited arguments
- B. A function inside another function
- C. A function added to an existing type without inheriting from it (correct)
- D. A function marked open
What does mapOf("a" to 1) create?
- A. A list of pairs only
- B. A read-only map with key "a" and value 1 (correct)
- C. A mutable map
- D. A range
What does the lateinit modifier allow?
- A. Declaring a constant
- B. Skipping the constructor
- C. Initializing a non-null var later, after declaration (correct)
- D. Lazy computing a val
What does by lazy do for a val?
- A. Computes the value on first access and caches it (correct)
- B. Makes the value mutable
- C. Computes the value at compile time
- D. Delays the program start
What is a sealed class used for?
- A. A thread-safe class
- B. A restricted class hierarchy whose subclasses are known at compile time (correct)
- C. A class that cannot have methods
- D. A class with private fields only
What does the until keyword in for (i in 0 until 5) produce?
- A. 1 to 5
- B. 0 to 4 (correct)
- C. 0 to 5
- D. 1 to 4
What does step 2 do in for (i in 1..10 step 2)?
- A. Visits every second list
- B. Visits 2, 4, 6, 8, 10
- C. Visits 1, 3, 5, 7, 9 (correct)
- D. Repeats each number twice
Which function returns the first element of a list or null if the list is empty?
- A. first()
- B. firstOrNull() (correct)
- C. head()
- D. getFirst()
Which type does a Kotlin function return when it has no useful value?
- A. Nothing
- B. Unit (correct)
- C. Void
- D. Null
Which keyword declares a compile-time constant in Kotlin?
- A. static val
- B. final val
- C. let
- D. const val (correct)
What is the difference between == and === in Kotlin?
- A. == checks references; === checks content
- B. === is only for numbers
- C. == checks structural equality; === checks if two references are the same object (correct)
- D. They are identical
What is a coroutine in Kotlin?
- A. A database connection
- B. A type of class
- C. A lightweight unit of work that can suspend without blocking a thread (correct)
- D. A new operating system thread
What does the suspend modifier on a function mean?
- A. It runs on a separate process
- B. It can pause and resume and must be called from a coroutine or another suspend function (correct)
- C. It runs only once
- D. It cannot return a value
Which builder starts a coroutine and returns a Deferred result?
- A. launch
- B. thread
- C. runBlocking only
- D. async (correct)
What does launch return?
- A. A Job (correct)
- B. A Deferred
- C. The result value
- D. Unit
Which dispatcher is meant for blocking IO work such as file or network calls?
- A. Dispatchers.Main
- B. Dispatchers.Default
- C. Dispatchers.IO (correct)
- D. Dispatchers.Unconfined
What is the Nothing type used for?
- A. Functions that return null
- B. Optional parameters
- C. Functions that never return normally, such as one that always throws (correct)
- D. Empty lists
What does the inline modifier do to a higher-order function?
- A. Runs it on the main thread
- B. Makes it private
- C. Copies the function body and its lambda into the call site (correct)
- D. Makes it recursive
Inside a when expression on a sealed class, what lets you skip the else branch?
- A. Using a data class
- B. Adding @Suppress
- C. Marking the function inline
- D. Covering every subclass (correct)
What does the scope function apply return?
- A. The result of the lambda
- B. The object it was called on (correct)
- C. null
- D. Unit
What does the scope function let return?
- A. Unit
- B. Always null
- C. The object it was called on
- D. The result of the lambda (correct)
What does a smart cast mean in Kotlin?
- A. Casting with the as keyword
- B. Converting numbers silently
- C. Casting at runtime only
- D. The compiler automatically casts a value after a type or null check (correct)
What is a Flow in Kotlin coroutines?
- A. A cold asynchronous stream of values (correct)
- B. A blocking list
- C. A thread pool
- D. A UI layout
What is structured concurrency?
- A. Running coroutines in alphabetical order
- B. Using only one thread
- C. Coroutines are tied to a scope so they are cancelled and awaited together (correct)
- D. Starting coroutines with GlobalScope
What is the effect of the reified keyword on an inline function's type parameter?
- A. The type is erased
- B. The function becomes generic over Any only
- C. The type becomes nullable
- D. The type is available at runtime inside the function (correct)
Which interface do Kotlin's destructuring declarations on data classes rely on?
- A. Serializable
- B. componentN() functions (correct)
- C. Iterable
- D. Comparable
What does the copy() function of a data class do?
- A. Copies the class definition
- B. Creates a new instance, optionally changing some properties (correct)
- C. Deep-copies every nested object
- D. Clones the object in place
What does the out keyword in List<out T> mean?
- A. The type is invariant
- B. The list is read-write
- C. The type is covariant: it is only produced, not consumed (correct)
- D. The type is contravariant
Which function blocks the current thread until its coroutines complete and is mainly used in main or tests?
- A. runBlocking (correct)
- B. delay
- C. launch
- D. async
What does delay() do inside a coroutine?
- A. Cancels the coroutine
- B. Blocks the thread with Thread.sleep
- C. Suspends the coroutine without blocking the thread (correct)
- D. Stops the program
What is the difference between a List and a MutableList in Kotlin?
- A. They are the same type
- B. List has no methods to change it; MutableList adds add and remove (correct)
- C. List is always empty
- D. MutableList cannot hold nulls