Quiz: Kotlin
Kotlin questions from real interviews as a quiz, with an explanation for every option.
Try it: 5 questions
Loading…
Sample questions
Which statement best describes
whenin Kotlin?- It is shorthand for
ifthat allows only one condition and oneelsebranch. - It is an expression for iterating over collection elements that always returns a list of results.
- It is a selection construct that can be an expression or a statement and test values, types, and conditions.
- It is a statement that compares one variable only with constants, like Java's
switch.
- It is shorthand for
How do
suspendfunctions let coroutines perform asynchronous operations without blocking a thread?- They create a separate thread for each operation and block it until a result is available.
- They replace asynchronous operations with synchronous calls through
runBlocking. - They suspend the coroutine and later resume it through a
Continuation, without blocking the thread. - They run all operations in parallel and automatically combine their results.
What advantages does destructuring provide in Kotlin? Select three options.
- It assigns an object's components to separate variables in a concise declaration.
- It lets you skip unwanted components with
_. - It guarantees faster execution than accessing properties directly.
- It automatically converts an object to JSON without libraries.
- It makes it convenient to access keys and values when iterating over a
Map.
How do you overload the
+operator for a custom type in Kotlin?- Declare an
addfunction with theoperatormodifier - Declare a
plusfunction without usingoperator - Declare a
plusfunction with theoperatormodifier - Override the custom type's
toStringfunction
- Declare an
Which factors can make PostgreSQL choose a Seq Scan in production and an Index Scan in dev/ft, even when the indexes are the same? Choose three.
- Differences in data volume and the fraction of rows matching the query
- Differences in cost settings, such as
random_page_costandseq_page_cost - The current CPU load and actual cache contents directly change the planner's scan choice
- With the same indexes, PostgreSQL must choose the same plan
- Differences in, or stale, planner statistics
Which statements about coroutines and data streams in Kotlin are correct?
Dispatchers.IOis primarily intended for CPU-intensive computations.- A coroutine usually occupies a separate OS thread for its entire lifetime.
- A
Channellets coroutines pass data to one another. - A
suspendfunction can pause execution without blocking a thread. Flowis a cold asynchronous stream that can emit multiple values.
Select the three correct statements about PostgreSQL
JSONandJSONBand their mapping in Hibernate.JSONBpreserves the original whitespace and key order just likeJSON.JSONBstores a parsed representation, does not retain the original formatting, and supports indexing.- Hibernate 6 cannot map JSON without a custom
UserType. - Hibernate's JSON support depends on the version: Hibernate 6 has built-in mapping, while older versions often need third-party types.
JSONstores the original text, including whitespace and key order.
What is an extension function in Kotlin?
- A class function that uses
thisto access the class's private properties. - A method added directly to a class's source code at runtime.
- A function declared outside a class that can be called like a method without changing the class itself.
- An overridden method in a subclass that extends the behavior of its parent class.
- A class function that uses
Which description of Kotlin is the most accurate?
- An Android framework that runs only on top of Java and is not used outside mobile apps.
- A statically typed language by JetBrains for Android, server-side, and multiplatform development.
- A dynamically typed language for web interfaces that runs only in the browser.
- A new version of Java designed to replace the JVM and incompatible with existing Java libraries.
How do you declare a type alias in Kotlin, and what does it mean?
- Use
alias; it creates a new type that is incompatible with the original. - Use
typealias; it can only be declared for functions. - Use
typealias; it gives an existing type another name, and the two are compatible. - Use
typealias; it creates a wrapper that must be converted to the original type.
- Use