VSkills Certified Kotlin Developer — Questions and Answers
Question 1: Which statement about Kotlin's `when` expression is correct?
- It can be used as both a statement and an expression (Correct answer)
- It requires break statements like Java's switch
- It must have an `else` branch always
- It only accepts integer values
Correct answer: It can be used as both a statement and an expression
`when` in Kotlin is flexible — it can act as a statement or return a value as an expression, and `else` is only required when used as an expression.
Question 2: What does `for (i in 1..5)` iterate over in Kotlin?
- 1 to 5 (Correct answer)
- 1 to 4
- 2 to 5
- 0 to 5
Correct answer: 1 to 5
The `..` operator creates an inclusive range, so `1..5` iterates over 1, 2, 3, 4, and 5.
Question 3: Which of the following will cause a compilation error in Kotlin when `x` is of type `String?`?
- x.doSomething() (Correct answer)
- if (x != null) x.doSomething()
- x ?: defaultValue
- x?.doSomething()
Correct answer: x.doSomething()
Calling `x.doSomething()` directly on a nullable type without null handling causes a compilation error; Kotlin enforces null safety at compile time.
Question 4: What does `when` replace in Kotlin compared to Java?
- try-catch
- if-else
- for loop
- switch (Correct answer)
Correct answer: switch
Kotlin's `when` expression is a more powerful replacement for Java's `switch` statement, supporting arbitrary conditions.
Question 5: What is a lambda with receiver in Kotlin?
- A lambda that returns the receiver object
- A lambda defined inside an extension function
- A lambda that takes a receiver as a parameter
- A lambda where `this` is bound to the specified receiver type, enabling DSL-like code (Correct answer)
Correct answer: A lambda where `this` is bound to the specified receiver type, enabling DSL-like code
A lambda with receiver (e.g., `String.() -> Unit`) is called with `this` bound to the receiver object, allowing direct member access without qualification.
Question 6: What does the `override` keyword do in Kotlin?
- Prevents further overriding
- Explicitly marks a method as overriding a parent class or interface member (Correct answer)
- Hides the parent method
- Creates a new method
Correct answer: Explicitly marks a method as overriding a parent class or interface member
The `override` modifier is required in Kotlin to explicitly indicate that a method overrides a member from a parent class or interface.
Question 7: What does the `?.` operator in Kotlin do?
- Performs a safe call on a nullable object (Correct answer)
- Checks equality of two nullable values
- Forces a non-null assertion
- Casts a type forcefully
Correct answer: Performs a safe call on a nullable object
The safe call operator `?.` calls a method or accesses a property only if the object is non-null; otherwise it returns null.
Question 8: What is the difference between `apply` and `also` in Kotlin?
- No difference
- `apply` uses `this` and returns the object; `also` uses `it` and returns the object (Correct answer)
- `apply` returns a transformed result; `also` returns the original
- `apply` is for nullables; `also` is for non-nullables
Correct answer: `apply` uses `this` and returns the object; `also` uses `it` and returns the object
Both `apply` and `also` return the receiver object, but `apply` exposes it as `this` for configuration, while `also` exposes it as `it` for side effects.
Question 9: What is a closure in Kotlin?
- A function with no parameters
- A sealed class with no subclasses
- A function that closes a file resource
- A lambda that captures variables from its enclosing scope (Correct answer)
Correct answer: A lambda that captures variables from its enclosing scope
A closure is a lambda or function literal that captures and can access variables from the surrounding scope.
Question 10: How do you make a Flow cold vs. hot in Kotlin?
- There is no distinction in Kotlin
- Cold Flows use collect(); hot Flows use emit()
- Cold Flows are built with flow{}; hot Flows are StateFlow or SharedFlow (Correct answer)
- Hot Flows use flowOf(); cold Flows use channelFlow()
Correct answer: Cold Flows are built with flow{}; hot Flows are StateFlow or SharedFlow
Cold Flows (built with `flow{}`) start executing only when collected, while hot Flows like `StateFlow` and `SharedFlow` are always active.
Question 11: What is the correct way to define a nullable String in Kotlin?
- String
- Nullable<String>
- String!
- String? (Correct answer)
Correct answer: String?
In Kotlin, appending `?` to a type makes it nullable, so `String?` can hold a String value or null.
Question 12: Which scope function executes a block only when the value is non-null and passes it as `it`?
- with
- let (Correct answer)
- apply
- run
Correct answer: let
When called with `?.let { }`, the `let` scope function only executes its lambda block if the receiver is non-null, with the non-null value available as `it`.
Question 13: Which Kotlin class type cannot be instantiated and may have abstract members?
- data
- abstract (Correct answer)
- sealed
- inner
Correct answer: abstract
An `abstract` class cannot be instantiated directly and may contain abstract members that subclasses must implement.
Question 14: What is the Elvis operator in Kotlin?
- ?.
- ?: (Correct answer)
- !!
- ::
Correct answer: ?:
The Elvis operator `?:` returns the left-hand expression if non-null, otherwise returns the right-hand expression.
Question 15: What is `Pair` in Kotlin?
- A map with two entries
- A mutable two-element list
- A tuple with two comparable values
- A data class holding two values of potentially different types (Correct answer)
Correct answer: A data class holding two values of potentially different types
`Pair<A, B>` is a simple data class that holds two values, accessible via `.first` and `.second`.
Question 16: How do you prevent a Kotlin class from being subclassed?
- Kotlin classes cannot be subclassed by default (Correct answer)
- Using the `sealed` modifier
- Using the `final` modifier
- Using the `private` modifier
Correct answer: Kotlin classes cannot be subclassed by default
In Kotlin, all classes are `final` by default and cannot be subclassed unless explicitly marked with `open`.
Question 17: What is the difference between `List` and `MutableList` in Kotlin?
- List allows nulls; MutableList does not
- List is read-only; MutableList supports add/remove operations (Correct answer)
- There is no difference
- MutableList is faster than List
Correct answer: List is read-only; MutableList supports add/remove operations
`List` is a read-only interface in Kotlin, while `MutableList` extends it with mutation operations like `add()` and `remove()`.
Question 18: How do you create a mutable list in Kotlin?
- arrayListOf() only
- mutableListOf() (Correct answer)
- listOf()
- MutableList()
Correct answer: mutableListOf()
`mutableListOf()` creates a `MutableList<T>` backed by an `ArrayList`, allowing add, remove, and update operations.
Question 19: A Kotlin application's entry point is the
- user function
- system function
- main function (Correct answer)
- access function
Correct answer: main function
Explanation: <br> Both procedural and object-oriented programming are supported in Kotlin. If you've worked with procedural languages before, you're probably aware that main () is the program's entry point. In the same way, the main () function (or method) in a Kotlin file represents the starting point for a Kotlin program.
Question 20: Which coroutine builder launches a new coroutine and returns a Job?
- launch (Correct answer)
- withContext
- runBlocking
- async
Correct answer: launch
`launch` is a coroutine builder that starts a new coroutine and returns a `Job` handle for managing it.
Question 21: What does the `return@label` syntax do in Kotlin?
- Throws an exception
- Restarts the enclosing loop
- Returns from the enclosing function
- Returns from a specific lambda or function using a label (Correct answer)
Correct answer: Returns from a specific lambda or function using a label
Labeled returns (`return@label`) allow returning from a specific lambda or function scope rather than the enclosing function.
Question 22: Which of the following is the entry point of a Kotlin program?
- fun init()
- fun begin()
- fun start()
- fun main() (Correct answer)
Correct answer: fun main()
Every Kotlin application starts execution from the `fun main()` function.
Question 23: What does `it` refer to inside a Kotlin lambda?
- The last expression value
- The return type
- The outer class instance
- The implicit single parameter of the lambda (Correct answer)
Correct answer: The implicit single parameter of the lambda
When a lambda has exactly one parameter, Kotlin allows you to omit the parameter declaration and refer to it as `it`.
Question 24: What is `lateinit` used for in Kotlin?
- Lazy initialization of nullable properties
- Marking properties as thread-safe
- Allowing non-nullable var properties to be initialized after declaration without using null (Correct answer)
- Declaring properties in interfaces
Correct answer: Allowing non-nullable var properties to be initialized after declaration without using null
`lateinit` allows non-nullable `var` properties to be declared without immediate initialization, useful for dependency injection and unit tests.
Question 25: What does `associateBy` do in Kotlin collections?
- Associates two collections by index
- Groups elements into a set
- Creates a bidirectional map
- Creates a Map from a collection using a key selector (Correct answer)
Correct answer: Creates a Map from a collection using a key selector
`associateBy` transforms a collection into a `Map<K, T>` using a key selector, with each element as the value.
Question 26: Which Kotlin function checks if all elements satisfy a predicate?
- none
- all (Correct answer)
- any
- every
Correct answer: all
`all` returns `true` only if every element in the collection satisfies the given predicate.
Question 27: What is an anonymous function in Kotlin?
- A function declared with `fun` but without a name (Correct answer)
- A function inside an interface
- A lambda with no parameters
- A function with no return type
Correct answer: A function declared with `fun` but without a name
An anonymous function uses the `fun` keyword without a name and supports explicit `return` statements, unlike lambdas.
Question 28: What is `remember` used for in Jetpack Compose?
- Creating animations
- Storing data in a database
- Preserving a value across recompositions (Correct answer)
- Defining navigation routes
Correct answer: Preserving a value across recompositions
`remember` stores a value in composition memory so it survives recompositions, but is reset if the composable leaves the composition.
Question 29: What is string interpolation in Kotlin?
- Concatenating strings with +
- Embedding expressions in strings using $ (Correct answer)
- Converting a number to a string
- Comparing two strings
Correct answer: Embedding expressions in strings using $
Kotlin supports string interpolation using the `$` symbol to embed variables or expressions directly inside string literals.
Question 30: Which keyword is used to declare an immutable variable in Kotlin?
- val (Correct answer)
- var
- const
- let
Correct answer: val
In Kotlin, `val` declares a read-only (immutable) variable, while `var` declares a mutable variable.
Question 31: How do you define a default parameter value in a Kotlin function?
- fun greet(name: String | "World")
- fun greet(name: String = 'World')
- fun greet(name: String = "World") (Correct answer)
- fun greet(name: String default "World")
Correct answer: fun greet(name: String = "World")
Default parameter values are assigned using `=` after the type declaration, with the value being a valid Kotlin expression.
Question 32: What is a companion object in Kotlin?
- A helper class for data serialization
- An object that accompanies a coroutine
- A singleton object declared inside a class that holds class-level members (Correct answer)
- An object that implements multiple interfaces
Correct answer: A singleton object declared inside a class that holds class-level members
A companion object is a singleton tied to its enclosing class, used to hold factory methods and constants accessible via the class name.
Question 33: What does the `groupBy` function do in Kotlin?
- Partitions elements into two lists
- Groups elements into a map by a key selector function (Correct answer)
- Removes duplicate elements
- Sorts elements into groups by value
Correct answer: Groups elements into a map by a key selector function
`groupBy` returns a `Map<K, List<T>>` where each key maps to a list of elements matching that key from the key selector.
Question 34: What does `reduce` do differently from `fold` in Kotlin?
- They are identical
- `reduce` uses the first element as the initial accumulator; `fold` requires an explicit initial value (Correct answer)
- `reduce` requires an initial value; `fold` does not
- `reduce` returns a nullable result; `fold` does not
Correct answer: `reduce` uses the first element as the initial accumulator; `fold` requires an explicit initial value
`reduce` uses the first element as the starting accumulator and throws if the collection is empty; `fold` always requires an explicit initial value.
Question 35: What is the default visibility modifier in Kotlin?
- protected
- public (Correct answer)
- internal
- private
Correct answer: public
In Kotlin, declarations are `public` by default, meaning they are visible everywhere.
Question 36: What is a DSL in Kotlin and how are extension functions used to build them?
- A Domain-Specific Language built using extension functions and lambdas with receivers for readable configuration code (Correct answer)
- A test framework
- A database query language
- A debugging syntax layer
Correct answer: A Domain-Specific Language built using extension functions and lambdas with receivers for readable configuration code
Kotlin DSLs use extension functions, lambdas with receivers, and infix functions to create readable, type-safe configuration APIs like Gradle Kotlin DSL or HTML builders.
Question 37: What is tail recursion in Kotlin and how is it enabled?
- Recursion using a list as a stack
- Recursive calls optimized by the compiler using the `tailrec` modifier to avoid stack overflow (Correct answer)
- Calling a function from the end of another function
- Recursion with memoization
Correct answer: Recursive calls optimized by the compiler using the `tailrec` modifier to avoid stack overflow
The `tailrec` modifier tells the Kotlin compiler to optimize a recursive function into a loop, preventing stack overflow for deep recursion.
Question 38: Which function removes duplicate elements from a Kotlin list?
- deduplicate()
- toSet()
- distinct() (Correct answer)
- unique()
Correct answer: distinct()
`distinct()` returns a new list with all duplicate elements removed, preserving the order of first occurrence.
Question 39: What is Retrofit used for in Android Kotlin development?
- Database migrations
- A type-safe HTTP client for making network requests (Correct answer)
- Thread management
- UI layout inflation
Correct answer: A type-safe HTTP client for making network requests
Retrofit is a type-safe HTTP client for Android that converts REST API endpoints into Kotlin interface methods.
Question 40: In Kotlin, there are two types of constructors
- Primary & Secondary constructor (Correct answer)
- None of the above
- Default & No-arg constructor
- Parameterized & constant Constructor
Correct answer: Primary & Secondary constructor
Explanation: <br> There are two constructors in Kotlin: primary constructor and secondary constructor. Primary constructor is a straightforward approach to initialize a class, while secondary constructor allows you to include additional initialization logic.
Question 41: Can extension functions access private members of the extended class?
- Yes, but only for data classes
- Yes, always
- No, they can only access public and internal members (Correct answer)
- Yes, but only within the same module
Correct answer: No, they can only access public and internal members
Extension functions do not have access to private or protected members of the class they extend; they can only use publicly visible APIs.
Question 42: What symbol is appended to a type to make it nullable in Kotlin?
- ~
- ? (Correct answer)
- !
- *
Correct answer: ?
In Kotlin, appending `?` to a type name makes it nullable, allowing the variable to hold null values.
Question 43: Which function is used to convert a String to an Int in Kotlin?
- castInt()
- parseInt()
- toInt() (Correct answer)
- Int(string)
Correct answer: toInt()
Kotlin's `String.toInt()` extension function converts a string to an `Int`, throwing `NumberFormatException` if invalid.
Question 44: What is a `vetoable` delegate in Kotlin?
- A delegate that makes a property read-only after first assignment
- A delegate that logs property changes
- A delegate that lets you veto (reject) a new value before it is set (Correct answer)
- A delegate that synchronizes access
Correct answer: A delegate that lets you veto (reject) a new value before it is set
`Delegates.vetoable` calls a handler when a value is about to be assigned; if the handler returns `false`, the assignment is rejected.
Question 45: What is the output of `'A'.code` in Kotlin?
- Char
- 65 (Correct answer)
- 1
- A
Correct answer: 65
The `.code` property on a `Char` returns its Unicode code point as an `Int`; for 'A' that is 65.
Question 46: What does `!!` do in Kotlin?
- Checks if a value is not null
- Non-null assertion that throws NullPointerException if null (Correct answer)
- Double negation operator
- Safe call on nullable
Correct answer: Non-null assertion that throws NullPointerException if null
The `!!` operator asserts that the value is non-null and throws `KotlinNullPointerException` if the value is null.
Question 47: What is partial application in Kotlin?
- Applying a function to part of a collection
- Using default parameters
- A failed function call
- Calling a function with fewer arguments than required and getting a new function for the rest (Correct answer)
Correct answer: Calling a function with fewer arguments than required and getting a new function for the rest
Partial application fixes some arguments of a function, returning a new function that accepts the remaining arguments.
Question 48: What is an extension property in Kotlin?
- A property added to an existing class without modifying its source (Correct answer)
- A property with a custom getter and setter
- A delegated property
- A property that extends the type of another property
Correct answer: A property added to an existing class without modifying its source
Extension properties add computed properties to existing classes without modifying them, but they cannot have backing fields.
Question 49: What is `mutableStateOf` in Jetpack Compose?
- A coroutine state machine
- A thread-safe map implementation
- A way to create a mutable list
- A state holder that triggers recomposition when its value changes (Correct answer)
Correct answer: A state holder that triggers recomposition when its value changes
`mutableStateOf` creates an observable state object; when its value changes, Compose schedules a recomposition of composables reading the state.
Question 50: Which modifier makes a class member accessible only within the same file in Kotlin?
- internal
- private (Correct answer)
- protected
- file-private
Correct answer: private
In Kotlin, `private` at the top level restricts visibility to the file in which it is declared.
Question 51: Which Kotlin function returns only elements of a collection that satisfy a predicate?
- find
- filter (Correct answer)
- any
- map
Correct answer: filter
`filter` returns a new collection containing only elements for which the given predicate returns true.
Question 52: What is the type of a lambda that takes an Int and returns a String in Kotlin?
- Lambda<Int, String>
- Int => String
- Function<Int, String>
- (Int) -> String (Correct answer)
Correct answer: (Int) -> String
Kotlin function types use the `(ParameterTypes) -> ReturnType` syntax, so an Int-to-String lambda is `(Int) -> String`.
VSkills Certified Kotlin Developer
The VSkills Certified Kotlin Developer exam validates proficiency in Kotlin programming, covering language fundamentals, object-oriented and functional programming, collections, coroutines, and advanced language features like extensions and delegates.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds