VSkills Certified Kotlin Developer — Questions and Answers
Question 1: What is the default visibility modifier in Kotlin?
- private
- internal
- protected
- public (Correct answer)
Correct answer: public
In Kotlin, declarations are `public` by default, meaning they are visible everywhere.
Question 2: What will `println(10 / 3)` output in Kotlin?
- 3.333...
- 4
- 3.33
- 3 (Correct answer)
Correct answer: 3
Integer division in Kotlin truncates the decimal, so 10 divided by 3 equals 3.
Question 3: What does `run` scope function do when called on an object in Kotlin?
- Starts a coroutine
- Calls a lambda with the object as `this` and returns the lambda result (Correct answer)
- Prints the object to console
- Returns the object unchanged
Correct answer: Calls a lambda with the object as `this` and returns the lambda result
`run` calls the block with the receiver as `this` and returns the result of the block, useful for transforming objects.
Question 4: 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 5: What keyword makes a Kotlin class open for inheritance?
- abstract
- inheritable
- open (Correct answer)
- extends
Correct answer: open
Kotlin classes are final by default; the `open` keyword must be added explicitly to allow a class to be subclassed.
Question 6: Which operator is used to perform a non-null assertion in Kotlin?
- !! (Correct answer)
- ?:
- &&
- ?.
Correct answer: !!
The `!!` operator asserts that a nullable expression is non-null, throwing a NullPointerException if it is null.
Question 7: What does `with` scope function do in Kotlin?
- Executes code only if the object is non-null
- Creates a new scope with imports
- Calls a lambda with an object as `this` and returns the lambda result, without being an extension function (Correct answer)
- Wraps an object in a nullable container
Correct answer: Calls a lambda with an object as `this` and returns the lambda result, without being an extension function
`with` is a non-extension function that takes an object as a parameter, calls the lambda with it as `this`, and returns the lambda result.
Question 8: What is a lambda expression in Kotlin?
- A type alias
- A class with a single method
- An anonymous function literal that can be stored in a variable or passed as an argument (Correct answer)
- A named function
Correct answer: An anonymous function literal that can be stored in a variable or passed as an argument
A lambda in Kotlin is an anonymous function literal enclosed in `{}` that can be passed as a value or stored in a variable.
Question 9: What is the `Set` interface in Kotlin?
- An ordered collection that allows duplicates
- A sorted list implementation
- A key-value collection
- An unordered collection that does not allow duplicate elements (Correct answer)
Correct answer: An unordered collection that does not allow duplicate elements
`Set` is a collection that holds unique elements; it has no defined order in the base interface and does not allow duplicates.
Question 10: What is a receiver in the context of Kotlin extension functions?
- The parameter list of the function
- The object on which the extension function is called, accessible as `this` (Correct answer)
- The return value of the function
- The class that defines the extension
Correct answer: The object on which the extension function is called, accessible as `this`
The receiver is the instance on which an extension function is invoked; inside the extension, it can be accessed implicitly as `this`.
Question 11: What is property delegation in Kotlin?
- Delegating the implementation of a property's get/set to another object (Correct answer)
- Making a property abstract
- Creating a copy of a property
- Passing a property to a function
Correct answer: Delegating the implementation of a property's get/set to another object
Property delegation lets you hand off the `get` and `set` implementations to a delegate object, enabling reusable property behavior.
Question 12: What does the `fold` function do in Kotlin?
- Accumulates a value starting from an initial value (Correct answer)
- Removes duplicate elements
- Flattens a nested collection
- Groups elements by a key
Correct answer: Accumulates a value starting from an initial value
`fold` accumulates a result by applying an operation to each element along with a running accumulator, starting from an initial value.
Question 13: What is the difference between `abstract class` and `interface` in Kotlin?
- There is no difference
- Abstract classes can have constructors and state; interfaces cannot have constructors or mutable state (Correct answer)
- Interfaces can only have abstract methods
- Interfaces support state; abstract classes do not
Correct answer: Abstract classes can have constructors and state; interfaces cannot have constructors or mutable state
Abstract classes can have constructors, state (fields), and initialization logic; interfaces can have abstract and default methods but no constructors or stored mutable state.
Question 14: Which keyword is used to define a class in Kotlin?
- class (Correct answer)
- object
- struct
- type
Correct answer: class
The `class` keyword is used to define a class in Kotlin, just as in Java.
Question 15: What is the Elvis operator `?:` used for in Kotlin?
- Providing a default value when an expression is null (Correct answer)
- Type checking at runtime
- Declaring nullable types
- Performing safe casts
Correct answer: Providing a default value when an expression is null
The Elvis operator `?:` returns the left-hand value if it's not null, or the right-hand value as a fallback when it is null.
Question 16: How do you write a single-expression function in Kotlin?
- fun add(a: Int, b: Int) { return a + b }
- fun add(a: Int, b: Int) -> a + b
- def add(a: Int, b: Int) = a + b
- fun add(a: Int, b: Int) = a + b (Correct answer)
Correct answer: fun add(a: Int, b: Int) = a + b
Kotlin allows single-expression functions using the `=` syntax, omitting the curly braces and `return` keyword.
Question 17: What is the key difference between `Any` and `Any?` in Kotlin?
- There is no practical difference
- Any can hold null while Any? cannot
- Any? is the supertype of all types including nullable, while Any excludes null (Correct answer)
- Any is for objects only while Any? includes primitives
Correct answer: Any? is the supertype of all types including nullable, while Any excludes null
`Any?` is the supertype of all Kotlin types including nullable types, while `Any` is the supertype only of non-nullable types and cannot hold null.
Question 18: What does `!!` do in Kotlin?
- Non-null assertion that throws NullPointerException if null (Correct answer)
- Double negation operator
- Safe call on nullable
- Checks if a value is not null
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 19: What is the difference between `lazy` and `lateinit` in Kotlin?
- `lazy` is for val properties with computed initialization; `lateinit` is for var properties initialized externally (Correct answer)
- No difference
- `lateinit` is thread-safe; `lazy` is not
- `lazy` supports primitives; `lateinit` does not
Correct answer: `lazy` is for val properties with computed initialization; `lateinit` is for var properties initialized externally
`lazy` is used with `val` and initializes via a lambda on first access, while `lateinit` is for `var` properties that will be set later by external code.
Question 20: What is a sealed class in Kotlin used for?
- Enabling multiple inheritance
- Preventing any instantiation
- Restricting class hierarchies to a fixed set of subclasses (Correct answer)
- Creating singletons
Correct answer: Restricting class hierarchies to a fixed set of subclasses
A `sealed class` restricts its subclasses to be defined in the same file, enabling exhaustive `when` expressions over class hierarchies.
Question 21: What is a closure in Kotlin?
- A function that closes a file resource
- A function with no parameters
- A lambda that captures variables from its enclosing scope (Correct answer)
- A sealed class with no subclasses
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 22: What is the correct way to define a nullable String in Kotlin?
- String!
- String? (Correct answer)
- String
- Nullable<String>
Correct answer: String?
Appending `?` to a type in Kotlin marks it as nullable, allowing it to hold null values.
Question 23: What is an abstract class in Kotlin?
- A class with no constructor
- A class that cannot be instantiated and may have abstract members (Correct answer)
- A class with only one subclass
- A class that cannot have properties
Correct answer: A class that cannot be instantiated and may have abstract members
An `abstract` class in Kotlin cannot be instantiated directly and may contain abstract members that subclasses must implement.
Question 24: What is a DSL in Kotlin and how are extension functions used to build them?
- A database query language
- A debugging syntax layer
- A test framework
- A Domain-Specific Language built using extension functions and lambdas with receivers for readable configuration code (Correct answer)
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 25: Which keyword is used to define a constant at the top level in Kotlin?
- static val
- final val
- immutable val
- const val (Correct answer)
Correct answer: const val
`const val` declares a compile-time constant in Kotlin, which must be a primitive type or String at the top level or inside an object.
Question 26: What does `flatMap` do in Kotlin?
- Flattens a nested list into a single list
- Maps elements and flattens the resulting nested lists into one (Correct answer)
- Filters and maps simultaneously
- Groups elements into sublists
Correct answer: Maps elements and flattens the resulting nested lists into one
`flatMap` applies a transformation that returns a collection for each element, then flattens all results into a single list.
Question 27: Which of the following correctly declares a Kotlin function that returns an Int?
- def add(a: Int, b: Int): Int
- function add(a: Int, b: Int): Int
- fun add(a: Int, b: Int) Int
- fun add(a: Int, b: Int): Int (Correct answer)
Correct answer: fun add(a: Int, b: Int): Int
Kotlin functions use the `fun` keyword, with parameter types and return type separated by a colon.
Question 28: What is the purpose of generics in Kotlin?
- To allow functions to accept any number of parameters
- To avoid using nulls
- To make classes serializable
- To enable type-safe reusable code that works with different types (Correct answer)
Correct answer: To enable type-safe reusable code that works with different types
Generics allow writing type-safe classes and functions that work across different types without duplicating code.
Question 29: Which built-in higher-order function applies a transformation to each element of a collection?
- map (Correct answer)
- filter
- reduce
- fold
Correct answer: map
`map` applies a given transformation function to each element of a collection and returns a new list of results.
Question 30: What is the difference between `StateFlow` and `SharedFlow` in Kotlin?
- SharedFlow holds state; StateFlow does not
- StateFlow holds the latest value and replays it to new collectors; SharedFlow is configurable (Correct answer)
- There is no difference
- StateFlow is hot and holds state; SharedFlow is cold and stateless
Correct answer: StateFlow holds the latest value and replays it to new collectors; SharedFlow is configurable
`StateFlow` always holds and replays the latest value to new subscribers, while `SharedFlow` is configurable with custom replay and buffering.
Question 31: What is `Pair` in Kotlin?
- A tuple with two comparable values
- A data class holding two values of potentially different types (Correct answer)
- A mutable two-element list
- A map with two entries
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 32: What is the `Nothing` type in Kotlin primarily used for?
- Representing void functions
- Generic type wildcards
- Storing null values
- Functions that always throw or loop infinitely (Correct answer)
Correct answer: Functions that always throw or loop infinitely
`Nothing` represents a value that never exists; it's the return type of functions like `throw` expressions or infinite loops that never complete normally.
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