Coding Studio

Learn & Grow together.

Top 20 Kotlin interview questions and answers 2025-2026

1️⃣ What are the key features of Kotlin?

Answer:

  • Concise and expressive syntax
  • Null safety (? and !!)
  • Interoperable with Java
  • Extension functions
  • Coroutines for asynchronous programming
  • Data classes and Sealed classes

2️⃣ Difference between val and var.

Answer:

  • val → immutable (like final in Java)
  • var → mutable, value can change

3️⃣ What are Data Classes in Kotlin?

Answer:

  • Classes used to hold data
  • Auto-generates: toString(), equals(), hashCode(), copy(), componentN()
data class User(val name: String, val age: Int)

4️⃣ Explain Null Safety in Kotlin.

Answer:

  • Kotlin prevents NullPointerException using ? operator
  • Safe call: user?.name
  • Elvis operator: val length = user?.name?.length ?: 0
  • Not-null assertion: user!!.name (throws exception if null)

5️⃣ Difference between == and ===.

Answer:

  • == → structural equality (checks values)
  • === → referential equality (checks if objects point to same memory)

6️⃣ What are Extension Functions?

Answer:

  • Add functions to existing classes without inheritance
fun String.addExclamation() = this + "!"
val text = "Hello".addExclamation()  // "Hello!"

7️⃣ Explain Sealed Classes.

Answer:

  • Used for restricted class hierarchies
  • All subclasses known at compile time
  • Useful in when expressions
sealed class Result
data class Success(val data: String) : Result()
data class Error(val error: String) : Result()

8️⃣ Difference between open, abstract, and final classes.

Answer:

  • final → default, cannot inherit
  • open → can be inherited
  • abstract → cannot be instantiated, may have abstract members

9️⃣ What are Coroutines in Kotlin?

Answer:

  • Lightweight threads for asynchronous programming
  • Use suspend functions, launch, async, and withContext
  • Reduces callback hell and improves performance

10️⃣ Difference between launch and async.

Answer:

  • launch → returns Job, does not return result
  • async → returns Deferred<T>, can return result using await()

11️⃣ Explain lateinit vs lazy.

Answer:

  • lateinit → for var, initialized later, avoids null
  • lazy → for val, initialized on first access
lateinit var name: String
val age: Int by lazy { 25 }

12️⃣ Difference between object and companion object.

Answer:

  • object → singleton instance
  • companion object → static members in class
class MyClass {
    companion object { val id = 1 }
}

13️⃣ Explain Higher-Order Functions.

Answer:

  • Functions that take functions as parameters or return functions
fun operate(x: Int, y: Int, op: (Int, Int) -> Int) = op(x, y)
val sum = operate(2, 3) { a, b -> a + b }  // 5

14️⃣ Difference between map, flatMap, filter in Kotlin.

Answer:

  • map → transforms each element
  • flatMap → maps and flattens nested collections
  • filter → selects elements based on condition

15️⃣ What are Inline Functions?

Answer:

  • Functions marked inline are inlined at call site
  • Reduces runtime overhead, useful for higher-order functions

16️⃣ Explain typealias in Kotlin.

Answer:

  • Provides alternative name for type
  • Useful for long generic types
typealias StringMap = Map<String, String>
val data: StringMap = mapOf("a" to "1")

17️⃣ What are Kotlin Collections?

Answer:

  • List → ordered, can be mutable/immutable
  • Set → unique elements
  • Map → key-value pairs
  • Functions: map, filter, forEach, reduce, fold

18️⃣ Difference between Any, Unit, and Nothing.

Answer:

  • Any → supertype of all non-null types
  • Unit → like void in Java
  • Nothing → type with no value, useful for exceptions

19️⃣ Explain Kotlin Delegation.

Answer:

  • Kotlin supports delegating responsibilities to another object
  • by keyword used
interface Base { fun print() }
class BaseImpl(val x: Int) : Base { override fun print() = println(x) }
class Derived(b: Base) : Base by b

20️⃣ Difference between const val and val.

Answer:

  • val → read-only runtime constant
  • const val → compile-time constant, can only hold primitive types or String

Happy Learning..

Leave a Reply

Your email address will not be published. Required fields are marked *