These Kotlin interview questions and answers cover the core topics commonly asked in Kotlin, JVM, and Android developer interviews. The guide is organized by interview area so that freshers can revise the basics first and experienced developers can move directly to null safety, classes, functions, coroutines, and Android-specific Kotlin questions.
While preparing, focus on why a Kotlin feature exists and when to use it. Interviewers often ask follow-up questions about null safety, data classes, scope functions, coroutines, Java interoperability, and Android lifecycle-safe code.
Kotlin Interview Topics to Prepare
| Interview area | Topics to revise |
|---|---|
| Kotlin basics | Language purpose, Kotlin vs Java, val, var, type inference, visibility modifiers. |
| Null safety | Nullable types, safe calls, Elvis operator, not-null assertion, smart casts. |
| Classes and objects | Data classes, sealed classes, object declarations, companion objects, inheritance. |
| Functions | Lambdas, higher-order functions, extension functions, scope functions, inline functions. |
| Coroutines | Suspend functions, launch, async, cancellation, structured concurrency. |
| Android Kotlin | lateinit, lazy, lifecycle-aware scopes, Kotlin-Java interoperability. |
Kotlin Basics Interview Questions for Freshers
What is Kotlin and why was it created?
Kotlin is a modern, statically typed programming language created by JetBrains. It runs on the JVM, works with Java libraries, and can also target JavaScript and native platforms. Kotlin was created to provide concise syntax, null safety, better type inference, extension functions, and smoother development on existing Java-based platforms.
What are the main features of Kotlin?
Important Kotlin features include null safety, concise syntax, data classes, extension functions, smart casts, higher-order functions, lambdas, coroutines, Java interoperability, sealed classes, and support for both object-oriented and functional programming styles.
What is the difference between Kotlin and Java?
Kotlin and Java both run on the JVM, but Kotlin reduces boilerplate and adds language-level features such as null safety, extension functions, data classes, smart casts, default arguments, named arguments, and coroutines. Kotlin also interoperates with Java, so Kotlin code can call Java code and Java code can call Kotlin declarations with some JVM-specific considerations.
What is the difference between val and var in Kotlin?
val is used for a read-only reference. Once assigned, the reference cannot be reassigned. var is used for a mutable variable whose value can be changed after initialization.
var count = 1
count = 2
val name = "Kotlin"
// name = "Java" // Compilation error
Kotlin Null Safety Interview Questions
What is null safety in Kotlin?
Null safety is Kotlin’s type-system feature that separates nullable and non-nullable types. A variable of type String cannot hold null, while a variable of type String? can hold null. This makes possible null values visible at compile time and reduces accidental NullPointerException errors.
What are safe call, Elvis operator, and not-null assertion in Kotlin?
The safe call operator ?. accesses a property or function only when the receiver is not null. The Elvis operator ?: supplies a fallback value when the expression on the left is null. The not-null assertion operator !! forces Kotlin to treat a nullable value as non-null, but it can throw a NullPointerException at runtime.
val userName: String? = null
val length = userName?.length
val displayName = userName ?: "Guest"
Explain smart casts in Kotlin.
Smart casts automatically cast a value after Kotlin verifies its type with checks such as is. This avoids repeated explicit casts when the compiler can prove that the value has the checked type.
fun printLength(value: Any) {
if (value is String) {
println(value.length)
}
}
Kotlin Class and Object Interview Questions
What are data classes in Kotlin?
A data class is used to hold data. Kotlin automatically generates useful functions such as equals(), hashCode(), toString(), copy(), and component functions for destructuring. A data class must have at least one parameter in the primary constructor.
data class User(val name: String, val age: Int)
What are sealed classes in Kotlin?
A sealed class represents a restricted hierarchy where all known subtypes are controlled. It is useful for modelling states such as success, error, loading, or empty results. In a when expression, sealed classes help the compiler check whether all cases are handled.
sealed class Result
data class Success(val data: String) : Result()
data class Error(val message: String) : Result()
fun handle(result: Result) = when (result) {
is Success -> result.data
is Error -> result.message
}
How does Kotlin handle inheritance?
Kotlin classes are final by default. A class must be marked with open to allow inheritance. Similarly, a function or property must be marked with open before a subclass can override it. Abstract classes can also be inherited, but they cannot be instantiated directly.
What is a companion object in Kotlin?
A companion object is an object declared inside a class using companion object. It holds members associated with the class rather than with a specific instance. It is commonly used for factory functions, constants, and Java-friendly static-like access when combined with JVM annotations where needed.
Kotlin Function Interview Questions
What are extension functions in Kotlin?
Extension functions let you add functions to an existing type without modifying its source code and without inheriting from it. They are resolved statically, so the function called depends on the declared receiver type.
fun String.addHello(): String {
return "Hello, $this"
}
val greeting = "World".addHello()
What are higher-order functions and lambda expressions in Kotlin?
A higher-order function takes another function as a parameter or returns a function. A lambda expression is an anonymous function that can be stored in a variable or passed to a higher-order function. Kotlin collections use this heavily in functions such as map, filter, and forEach.
val numbers = listOf(1, 2, 3, 4)
val evenNumbers = numbers.filter { it % 2 == 0 }
How do Kotlin scope functions differ: let, run, with, apply, and also?
Scope functions execute a block of code in the context of an object. let and also expose the object as it. run, with, and apply expose it as this. apply and also return the original object, while let, run, and with return the block result.
Kotlin Generics and Advanced Interview Questions
What are generics in Kotlin?
Generics allow classes, interfaces, and functions to work with types passed as parameters. They support reusable and type-safe code. Kotlin also supports declaration-site variance with out and in, which is a common follow-up topic in experienced-level interviews.
fun <T> List<T>.secondOrNull(): T? {
return if (size >= 2) this[1] else null
}
What are inline functions and reified type parameters in Kotlin?
An inline function is expanded at the call site, which can reduce overhead for some higher-order functions. A reified type parameter can be used only in an inline function and allows access to the actual type argument at runtime. This is useful for type checks, casts, and class references that would otherwise be affected by type erasure.
What are value classes in Kotlin?
Value classes, declared with value class and usually annotated with @JvmInline on the JVM, create type-safe wrappers around a single value. They are useful when you want stronger type meaning without the usual overhead of a wrapper object in many runtime cases.
Kotlin Coroutines Interview Questions
What is a coroutine in Kotlin?
A coroutine is a lightweight unit of asynchronous work that can suspend and resume without blocking the underlying thread. Coroutines are commonly used for network calls, database operations, file work, and other long-running tasks.
import kotlinx.coroutines.*
fun main() = runBlocking {
launch {
delay(1000L)
println("World!")
}
println("Hello,")
}
What is the difference between launch and async in Kotlin coroutines?
launch starts a coroutine and returns a Job. It is used when the caller does not need a result. async starts a coroutine and returns a Deferred, which can produce a result using await(). Both should be used inside a proper coroutine scope to follow structured concurrency.
What is structured concurrency in Kotlin?
Structured concurrency means coroutines should be launched in a defined scope so their lifetime is tied to that scope. This makes cancellation, error handling, and cleanup more predictable. In Android, developers usually prefer lifecycle-aware scopes such as viewModelScope or lifecycleScope instead of global coroutines.
Kotlin Android Interview Questions
Why is Kotlin widely used for Android development?
Kotlin is widely used for Android because it works with existing Java APIs, reduces boilerplate, supports null safety, and has coroutine support for asynchronous work. In Android interviews, connect Kotlin features with practical app code, such as safe null handling, concise data models, extension functions, sealed UI states, and lifecycle-aware coroutines.
What is the difference between lateinit and lazy in Kotlin?
lateinit is used with mutable non-null properties that will be initialized later. It works only with var properties and not with primitive types. lazy creates a read-only val whose value is computed only when it is accessed for the first time.
Kotlin Interview Revision Checklist
- Revise
valvsvar,==vs===, and nullable vs non-nullable types. - Practice data classes, sealed classes, companion objects, and inheritance examples.
- Understand lambdas, higher-order functions, extension functions, scope functions, inline functions, and reified type parameters.
- Prepare coroutine basics such as
suspend,launch,async, cancellation, and structured concurrency. - For Android interviews, revise
lateinit,lazy, lifecycle-aware scopes, Flow basics, and Kotlin-Java interoperability.
FAQs on Kotlin Interview Questions
Which Kotlin topics should freshers prepare first for interviews?
Freshers should start with Kotlin syntax, val and var, null safety, data classes, functions, collections, control flow, and basic object-oriented programming. After that, revise extension functions, lambdas, and simple coroutine concepts.
What Kotlin questions are common in Android interviews?
Android Kotlin interviews commonly ask about null safety, data classes, sealed classes for UI state, extension functions, lateinit vs lazy, scope functions, coroutines, Flow, and lifecycle-aware coroutine scopes such as viewModelScope.
How should I answer Kotlin coroutine interview questions?
Start with the idea that coroutines allow non-blocking asynchronous programming. Then explain suspend functions, coroutine builders like launch and async, dispatchers, cancellation, and structured concurrency. For Android roles, connect the answer to lifecycle-aware scopes.
Is Kotlin only used for Android development?
No. Kotlin is widely used for Android, but it is also used for backend development on the JVM, multiplatform projects, scripting, and applications that need Java interoperability with concise Kotlin syntax.
Editorial QA Checklist for Kotlin Interview Questions Page
- Confirm that duplicate Kotlin questions have been removed or consolidated into one clear answer.
- Check that each code example is short, accurate, and directly related to the question.
- Verify that Android-specific Kotlin questions include practical topics such as
lateinit,lazy, coroutines, and lifecycle-aware scopes. - Ensure that advanced Kotlin questions include inline functions, reified types, sealed classes, value classes, and Java interoperability.
- Review FAQ questions so they address Kotlin interview preparation rather than generic programming advice.
TutorialKart.com