Kotlin is a modern, open-source programming language developed by JetBrains, a software development company based in Russia. It was first released in 2011 but gained significant popularity in the following years, especially in the Android app development community. Kotlin is designed to be fully interoperable with Java, making it an excellent choice for building Android applications and other projects that rely on the Java Virtual Machine (JVM).
Kotlin has quickly grown to become one of the most popular programming languages for Android development and beyond. Its versatility, readability, and strong support for modern programming paradigms have contributed to its widespread adoption in various domains, including server-side development, web development, and enterprise applications. As an open-source language with an active community, Kotlin continues to evolve and expand its capabilities, attracting developers from diverse backgrounds and contributing to the overall growth of the Kotlin ecosystem.
You might like to know
Create an auto-grading quiz/assessment without any coding – try OnlineExamMaker today!
Article outline
- Part 1: 30 Kotlin quiz questions & answers
- Part 2: Download Kotlin questions & answers for free
- Part 3: Free online quiz creator – OnlineExamMaker
Part 1: 30 Kotlin quiz questions & answers
1. What is Kotlin primarily designed for?
a) Web development
b) Mobile app development
c) Data analysis
d) Game development
Answer: b) Mobile app development
2. Who developed the Kotlin programming language?
a) Google
b) JetBrains
c) Apple
d) Microsoft
Answer: b) JetBrains
3. Which virtual machine does Kotlin target for execution?
a) .NET
b) JVM (Java Virtual Machine)
c) LLVM
d) V8 (JavaScript engine)
Answer: b) JVM (Java Virtual Machine)
4. What is the level of Kotlin’s interoperability with Java?
a) Partially interoperable
b) Not interoperable
c) Fully interoperable
d) Interoperable only with Android projects
Answer: c) Fully interoperable
5. What does Kotlin’s “null safety” feature address?
a) Memory leaks
b) Lack of proper documentation
c) NullPointerExceptions (NPEs)
d) Slow performance
Answer: c) NullPointerExceptions (NPEs)
6. What keyword is used to declare a variable as nullable in Kotlin?
a) null
b) void
c) nullable
d) ?
Answer: d) ?
7. What is the default visibility modifier for top-level declarations in Kotlin?
a) private
b) public
c) protected
d) internal
Answer: b) public
8. Which Kotlin feature is used to automatically generate useful methods like `equals()`, `hashCode()`, and `toString()` for data classes?
a) Data annotations
b) Smart casts
c) Extension functions
d) Data classes
Answer: d) Data classes
9. What is the keyword used to define an extension function in Kotlin?
a) fun
b) extension
c) extend
d) infix
Answer: a) fun
10. What is the purpose of Kotlin’s `let` function?
a) To create a new variable
b) To define a constant value
c) To modify a variable’s value
d) To perform a series of operations on a non-null object
Answer: d) To perform a series of operations on a non-null object
11. What is the correct syntax to define a lambda expression in Kotlin?
a) lambda (x: Int) -> x * 2
b) {x: Int -> x * 2}
c) (x: Int) -> {x * 2}
d) (x: Int) => x * 2
Answer: b) {x: Int -> x * 2}
12. In Kotlin, what does the `lateinit` modifier do when applied to a property?
a) It delays the initialization of the property until it is accessed for the first time.
b) It allows the property to be assigned a value only once.
c) It marks the property as mutable.
d) It ensures that the property is always initialized with a non-null value.
Answer: a) It delays the initialization of the property until it is accessed for the first time.
13. Which Kotlin keyword is used to declare a class that cannot be instantiated and may contain abstract properties and methods?
a) final
b) open
c) abstract
d) sealed
Answer: c) abstract
14. How do you define a secondary constructor in Kotlin?
a) constructor()
b) init()
c) secondary()
d) constructor(args: String)
Answer: d) constructor(args: String)
15. In Kotlin, what does the “by” keyword do when used in a class declaration?
a) It specifies a superclass for the class.
b) It delegates the implementation of an interface to another object.
c) It defines a class property.
d) It specifies an extension function for the class.
Answer: b) It delegates the implementation of an interface to another object.
Part 2: Download Kotlin questions & answers for free
Download questions & answers for free
16. What is the purpose of the `when` keyword in Kotlin?
a) To define a loop
b) To define a conditional statement
c) To define an exception handler
d) To define a switch-case statement
Answer: d) To define a switch-case statement
17. What Kotlin feature is used for safely performing a type cast in situations where it may fail?
a) Smart casts
b) Safe casts
c) Smart conversions
d) Safe conversions
Answer: b) Safe casts
18. What is the output of the following Kotlin code snippet?
“`kotlin
val numbers = listOf(1, 2, 3, 4, 5)
val result = numbers.filter { it > 2 }.map { it * 2 }
println(result)
“`
a) [2, 4, 6, 8, 10]
b) [6, 8, 10]
c) [4, 6, 8, 10]
d) [2, 4]
Answer: b) [6, 8, 10]
19. In Kotlin, what does the “infix” keyword do when used with a function?
a) It makes the function an extension function.
b) It allows the function to be called without using parentheses.
c) It allows the function to be called using the infix notation.
d) It makes the function a higher-order function.
Answer: c) It allows the function to be called using the infix notation.
20. Which of the following is the correct syntax to declare a read-only property in Kotlin?
a) val myProperty: Int
b) var myProperty: Int
c) const myProperty: Int
d) let myProperty: Int
Answer: a) val myProperty: Int
21. In Kotlin, how do you perform string interpolation (inserting variables into a string)?
a) “Hello, $name!”
b) “Hello, {name}!”
c) “Hello, {name}!”
d) “Hello, {0}!”
Answer: a) “Hello, $name!”
22. What is the output of the following Kotlin code snippet?
“`kotlin
val list = listOf(1, 2, 3, 4, 5)
val sum = list.reduce { acc, i -> acc + i }
println(sum)
“`
a) 10
b) 15
c) 14
d) 120
Answer: b) 15
23. How do you create a new instance of a class in Kotlin without using the `new` keyword?
a) val obj = MyClass.new()
b) val obj = new MyClass()
c) val obj = MyClass()
d) val obj = create MyClass()
Answer: c) val obj = MyClass()
24. In Kotlin, what is the purpose of the `init` block in a class?
a) To initialize the primary constructor of
the class.
b) To define secondary constructors.
c) To initialize properties when the class is instantiated.
d) To define extension functions for the class.
Answer: c) To initialize properties when the class is instantiated.
25. What does the `run` function do in Kotlin?
a) It executes a block of code asynchronously.
b) It runs a coroutine in a separate thread.
c) It executes a block of code on a specified thread.
d) It allows you to perform a series of operations on a non-null object.
Answer: d) It allows you to perform a series of operations on a non-null object.
26. What is the purpose of the `with` function in Kotlin?
a) To define extension functions for a class.
b) To create a new instance of a class.
c) To specify the receiver object for a lambda expression.
d) To perform a series of operations on a non-null object.
Answer: c) To specify the receiver object for a lambda expression.
27. In Kotlin, what does the “by lazy” keyword do when used with a property?
a) It marks the property as mutable.
b) It defers the initialization of the property until it is accessed for the first time.
c) It allows the property to be assigned a value only once.
d) It specifies the visibility modifier for the property.
Answer: b) It defers the initialization of the property until it is accessed for the first time.
28. What is the correct syntax to define an interface in Kotlin?
a) class MyInterface {}
b) interface MyInterface {}
c) interface = MyInterface {}
d) interface = MyInterface
Answer: b) interface MyInterface {}
29. In Kotlin, how do you create a range of numbers from 1 to 10 (inclusive)?
a) val range = 1..10
b) val range = 1 to 10
c) val range = 1 until 11
d) val range = 1 upTo 10
Answer: a) val range = 1..10
30. What does the “inline” keyword do when used with a higher-order function in Kotlin?
a) It inlines the function call, reducing overhead.
b) It makes the function an extension function.
c) It allows the function to be called using the infix notation.
d) It allows the function to be called without using parentheses.
Answer: a) It inlines the function call, reducing overhead.
Part 3: Best online quiz making platform – OnlineExamMaker
OnlineExamMaker offers one stop solution for online examination and assessment. It would solve all your problems in preparation for the exam. Comes with a powerful candidate management system, you can add and import candidates, group similar aspirants, easily assign tests to the candidates to have a consistent track and monitor on the candidate’s performance.
Create Your Next Quiz/Exam with OnlineExamMaker