Loading ...

Kotlin Interview Questions & Answers (2025 Edition)

1. What is Kotlin?

Kotlin is a modern, statically typed programming language that runs on the JVM. It is officially supported by Google for Android development.

fun main() { println("Hello, Kotlin!") }

2. Difference between val and var

  • val: Immutable variable (like final in Java)

  • var: Mutable variable

val name = "Alice" // cannot reassign var age = 25 // can reassign age = 26

3. What is a data class?

Used to hold data. Kotlin automatically provides toString(), hashCode(), and copy().

data class Person(val name: String, val age: Int) val p = Person("Alice", 25) println(p) // Person(name=Alice, age=25)

4. Difference between == and ===

  • ==: Structural equality (compares content)

  • ===: Referential equality (compares references)

val a = "Hello" val b = "Hello" println(a == b) // true println(a === b) // may be true or false

5. What are nullable types?

Kotlin prevents null pointer exceptions with nullable types.

var name: String? = null println(name?.length) // safe call

6. What is a Kotlin function?

fun sum(a: Int, b: Int): Int { return a + b } println(sum(2, 3)) // 5

7. What is a Lambda in Kotlin?

Anonymous function used to simplify code.

val sum: (Int, Int) -> Int = { a, b -> a + b } println(sum(2,3)) // 5

8. Difference between fun and Unit

  • fun: Declares a function

  • Unit: Kotlin’s equivalent of void in Java

fun greet(): Unit = println("Hello")

9. What is the difference between List and MutableList

  • List: Immutable

  • MutableList: Can be modified

val list = listOf(1,2,3) val mutableList = mutableListOf(1,2,3) mutableList.add(4)

10. What is smart casting?

Kotlin automatically casts types after checking with is.

fun demo(obj: Any) { if (obj is String) println(obj.length) // no explicit cast needed }

Medium Questions (11–20)

11. Explain when expression

Kotlin’s enhanced switch.

fun demo(x: Int) = when(x) { 1 -> "One" 2 -> "Two" else -> "Other" }

12. Difference between open, final, and abstract

  • open: Can be inherited

  • final: Default, cannot be inherited

  • abstract: Must be implemented in subclasses


13. What is a companion object?

Allows static-like behavior in Kotlin.

class MyClass { companion object { fun create() = MyClass() } } val obj = MyClass.create()

14. Explain object keyword

Declares a singleton object.

object Singleton { val name = "Kotlin" } println(Singleton.name)

15. Difference between by lazy and lateinit

  • by lazy: Lazy initialization

  • lateinit: Non-null property initialized later

val name: String by lazy { "Alice" } lateinit var username: String

16. Explain extension functions

Add functions to existing classes without inheritance.

fun String.removeSpaces() = this.replace(" ", "") println("Hello World".removeSpaces()) // HelloWorld

17. Difference between Array and List

  • Array: Fixed size, mutable

  • List: Immutable by default


18. Explain higher-order functions

Functions that take or return functions.

fun applyOperation(x: Int, y: Int, op: (Int,Int)->Int) = op(x,y) println(applyOperation(2,3){a,b -> a+b}) // 5

19. Difference between const val and val

  • const val: Compile-time constant

  • val: Runtime constant


20. What are sealed classes?

Restricted class hierarchy, useful in state management.

sealed class Result class Success(val data: String): Result() class Error(val msg: String): Result()

Difficult Questions (21–30)

21. Explain coroutines in Kotlin

Lightweight threads for asynchronous programming.

import kotlinx.coroutines.* fun main() = runBlocking { launch { delay(1000); println("Hello") } println("World") }

22. Difference between runBlocking and launch

  • runBlocking: Blocks current thread

  • launch: Non-blocking coroutine


23. Explain Kotlin Flow

Asynchronous stream of data, similar to RxJava.

import kotlinx.coroutines.flow.* flowOf(1,2,3).collect { println(it) }

24. What are inline functions?

Reduce overhead of higher-order functions by inlining at compile-time.

inline fun runTwice(action: ()->Unit){ action() action() }

25. Difference between interface and abstract class

  • Interface: Multiple inheritance

  • Abstract class: Single inheritance, can have state


26. Explain delegation

Kotlin supports class delegation to reuse functionality.

interface Base { fun print() } class BaseImpl(val x: Int) : Base { override fun print() = println(x) } class Derived(b: Base) : Base by b

27. Explain typealiases

Aliases for long type definitions.

typealias Callback = (Int,String)->Unit

28. Explain reified generics

Allows type information at runtime for inline functions.

inline fun <reified T> isType(value: Any) = value is T

29. How to handle null safety

  • ?. safe call

  • ?: Elvis operator

  • !! force unwrap

val name: String? = null println(name?.length ?: 0) // 0

30. Difference between suspend and async

  • suspend: Marks function as coroutine

  • async: Launches coroutine and returns Deferred

✍️ By Not available | 2025-10-21T09:01:33.334Z

Call Our Course Advisors

IND: +91-98018 30173 / +91-70429 28331

US: +1-252 490 1033

UK: +44-121 3871751