Kotlin Quiz
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 18% Most missed: “Which statement declares a variable mileage whose value never changes and is inf…”

Kotlin MCQs For LinkedIn Skill Assessments.

Kotlin Quiz
Time left 00:00
25 Questions

1. What value is printed by println()?
kotlin
val set = setOf('apple', 'pear', 'orange', 'apple')
println(set.count())
2. Which is the correct declaration of an integer array with a size of 5?
3. The code below compiles and executes without issue, but is not idiomatic kotlin. What is a better way to impelement the 'printlln()'?
kotlin
fun main() {
val name: String = 'Amos'
val grade: Float = 95.5f
println('My name is ' + name + '. I score ' + grade + ' points on the last coding quiz.')
}
4. In the file main.kt, you are filtering a list of integers and want to use an already existing function, removeBadValues. What is the proper way to invoke the function from filter in the line below?
kotlin
val list2 = (80..100).toList().filter(_____)
5. The Kotlin .. operator can be written as which function?
6. You have two arrays, a and b. Which line combines a and b as a list containing the contents of both?
kotlin
val a = arrayOf(1, 2, 3)
val b = arrayOf(100, 200, 3000)
7. The code snippet below translates a database user to a model user. Because their names are both User, you must use their fully qualified names, which is cumbersome. You do not have access to either of the imported classes' source code. How can you shorten the type names?
kotlin
import com.tekadept.app.model.User
import com.tekadept.app.database.User
class UserService{
fun translateUser(user: com.tekadept.app.database.User): User =
com.tekadept.app.model.User('${user.first} ${user.last}')
}
8. For the Product class you are designing, you would like the price to be readable by anyone, but changeable only from within the class. Which property declaration implements your design?
9. The code below shows a typical way to show both index and value in many languages, including Kotlin. Which line of code shows a way to get both index and value more idiomatically?
kotlin
var ndx = 0;
for (value in 1..5){
println('$ndx - $value')
ndx++
}
10. You would like to print each score on its own line with its cardinal position. Without using 'var' or 'val', which method allows iteration with both the value and its position?
kotlin
fun main() {
val highScores = listOf(4000, 2000, 10200, 12000, 9030)
}
11. This code does not print any output to the console. What is wrong?
kotlin
firstName?.let {
println('Greeting $firstname!')
}
12. Class BB inherits from class AA. BB uses a different method to calculate the price. As shown, the code does not compile. What changes is needed to resolve the compilation error?
kotlin
open class AA() {
var price: Int = 0
get() = field + 10
}
class BB() : AA() {
var price: Int = 0
get() = field + 20
}
13. Kotlin interfaces and abstract classes are very similar. What is one thing abstract class can do that interfaces cannot?
14. You have created a data class, Point, that holds two properties, x and y, representing a point on a grid. You want to use the hash symbol for subtraction on the Point class, but the code as shown will not compile. How can you fix it?
kotlin
data class Point(val x: Int, val y: Int)
operator fun Point.plus(other: Point) = Point(x + other.x, y + other.y)
operator fun Point.hash(other: Point) = Point(x - other.x, y - other.y)
fun main() {
val point1 = Point(10, 20)
val point2 = Point(20, 30)
println(point1 + point2)
println(point1 # point2)
}
15. What is the entry point for a Kotlin application?
16. When the 'Airplane' class is instantiated, it displays 'Aircraft = null', not 'Aircraft = C130' why?
kotlin
abstract class Aircraft {
init { println('Aircraft = ${getName()}') }
abstract fun getName(): String
}
class Airplane(private val name: String) : Aircraft() {
override fun getName(): String = name
}
17. You have created an array to hold three strings. When you run the code bellow, the compiler displays an error. Why does the code fail?

val names = arrayOf(3)
names[3]= 'Delta'
18. You have written a function, sort(), that should accept only collections that implement the 'Comparable' interface. How can you restrict the function?
kotlin
fun sort(list: List): List {
return list.sorted()
}
19. What will happen when you try to build and run this code snippet?
kotlin
class SpecialFunction : () -> Unit {
override fun invoke() {
println('Invoked from an instance.')
}
}
fun main() {
try { SpecialFunction()() }
catch (ex: Exception) { println('An error occurred') }
}
20. This function generates Fibonacci sequence. Which function is missing?
kotlin
fun fibonacci() = sequence {
var params = Pair(0, 1)
while (true) {
___(params.first)
params = Pair(params.second, params.first + params.second)
}
}
21. You are upgrading a Java class to Kotlin. What should you use to replace the Java class's static fields?
22. The code below is expected to display the numbers from 1 to 10, but it does not. Why?
kotlin
val seq = sequence { yieldAll(1..20) }
.filter { it < 11 }
println(seq)
23. Given the code below, how can you write the line this.moveTo('LA') more concisely?
kotlin
data class Student (val name: String, var location: String) {
fun moveTo (newLoc: String) { location = newLoc }
}
fun main() {
Student ('Snow', 'Cologne').run {
this.moveTo ('LA')
}
24. You have written a snippet of code to display the results of the roll of a six-sided die. When the die displays from 3 to 6 inclusive, you want to display a special message. Using a Kotlin range, what code should you add?
kotlin
when (die) {
1 -> println('die is 1')
2 -> println('die is 2')
___ -> printlin('die is between 3 and 6')
else -> printlin('dies is unknown')
}
25. Which line of code shows how to call a Fibonacci function, bypass the first three elements, grab the next six, and sort the elements in descending order?

⚡ Recently practiced quizzes in this topic
Live quiz activity