100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Kotlin

Common Kotlin Interview Questions

The Kotlin questions interviewers ask most, with concise, technically accurate answers you can defend under follow-up.

Interview PrepIntermediate16 min readJul 8, 2026
Analogies

Overview

Kotlin interviews tend to circle back to the same handful of language features because they are exactly the areas where Kotlin diverges most sharply from Java: null safety, immutability, concise class declarations, and coroutines. Interviewers use these questions to check whether you understand *why* a feature exists, not just its syntax. This guide walks through the questions that come up again and again, with answers phrased the way you should phrase them out loud.

🏏

Cricket analogy: Like a bowling coach probing whether a trainee understands *why* a yorker works, not just how to bowl one, Kotlin interviews probe null safety, immutability, concise classes, and coroutines to test understanding of purpose, not just syntax.

Frequently Asked Questions

What is the difference between val and var?

var declares a mutable reference — you can reassign it after initialization. val declares a read-only (immutable) reference — once assigned, it cannot be reassigned. Note that val only makes the reference immutable, not necessarily the object it points to: a val list can still be a MutableList whose contents change, even though the variable itself can never point to a different object. Kotlin encourages val by default to reduce accidental mutation and make code easier to reason about.

🏏

Cricket analogy: Like a team's captaincy (var) that can be reassigned to a different player mid-series, versus a fixed squad list (val) that can't be swapped for a different squad object, even though players within that squad (a MutableList) can still be rotated in and out.

How does Kotlin's null safety system work?

Kotlin's type system distinguishes nullable types (String?) from non-nullable types (String) at compile time. A non-nullable type can never hold null, so the compiler rejects any assignment or dereference that could NPE without you explicitly handling it. This pushes null-pointer bugs from runtime crashes to compile-time errors, which is why Kotlin is often described as 'null-safe by design' rather than merely 'null-safe by convention.'

🏏

Cricket analogy: Like a scorecard field explicitly marked 'may be blank' (nullable String?) for a rain-abandoned match versus a mandatory 'final score' field that can never be empty (non-nullable String), Kotlin's compiler rejects any code that reads the mandatory field without checking, catching the bug before the match report ships.

What do ?., ?:, and !! do?

The safe-call operator ?. evaluates the expression to the right only if the receiver is non-null, otherwise it short-circuits to null. The Elvis operator ?: supplies a default value when the expression on its left is null, and is commonly chained after a safe call, e.g. user?.name ?: "Unknown". The not-null assertion operator !! forcibly casts a nullable value to non-null, throwing a NullPointerException immediately if it actually is null — it should be used sparingly, only when you can prove null is impossible.

🏏

Cricket analogy: Like checking nonStriker?.runs only if the non-striker is actually on the field (safe call), defaulting a rained-out score with ?: 0 (Elvis), or forcing captain!!.name when you're certain the captain is named, risking a crash if wrong.

kotlin
val city: String? = user?.address?.city
val displayCity = city ?: "Unknown"
// !! throws NPE if user is null — avoid unless you are certain
val forced = user!!.name

How do data classes differ from regular classes?

Marking a class 'data' tells the compiler to auto-generate equals(), hashCode(), toString(), a componentN() function per property (enabling destructuring), and a copy() function for creating modified shallow copies. A regular class gets none of this for free — you'd hand-write equals/hashCode/toString yourself. Data classes are meant for classes whose primary purpose is holding data; they require at least one parameter in the primary constructor and all primary-constructor parameters participate in the generated functions.

🏏

Cricket analogy: Like a standardized scorecard template that automatically generates the match summary, comparison, and a 'rematch with one lineup change' copy function, marking a Kotlin class data auto-generates equals(), hashCode(), toString(), componentN(), and copy(), while a regular class gets none of this for free.

When would you use a sealed class instead of an enum?

Enums represent a fixed set of instances where every case has the same shape (same properties). Sealed classes represent a fixed, closed set of subtypes where each subtype can carry different data and different structure — for example a Result sealed class with Success(data: T) and Error(message: String) subtypes that hold completely different fields. Because the subtype hierarchy is closed to the module/package that declares it, a when expression over a sealed class can be exhaustive without an else branch, which the compiler checks for you.

🏏

Cricket analogy: Like a fixed enum of MatchFormat (T20, ODI, Test, all sharing the same shape) versus a sealed MatchResult class where Win(margin: Int) and Abandoned(reason: String) carry completely different data; a when over the sealed class can skip else since the compiler knows every case.

What is an extension function and how is it dispatched?

An extension function lets you add a new function to an existing class without modifying its source or subclassing it, e.g. fun String.lastChar(): Char. Under the hood the compiler turns it into a static function that takes the receiver as its first parameter, so it never actually changes the class or has access to private members. Crucially, extension function resolution is static (resolved by the declared/compile-time type), not dynamic like real member functions — so if a subclass declares an extension with the same signature, the one that runs is chosen by the variable's static type, not its runtime type.

🏏

Cricket analogy: Like an unofficial commentator's stat (fun Batsman.strikeRate()) added on top of the official scorecard without modifying the board itself, Kotlin extension functions compile to static functions taking the receiver as a parameter, and which extension runs is decided by the declared type, not the actual player subtype at runtime.

What is the difference between lateinit and lazy?

lateinit lets you declare a non-null var without initializing it immediately, deferring initialization to later (commonly used for dependency injection or Android lifecycle fields); it only works on var properties of non-primitive, non-nullable types, and accessing it before initialization throws an exception. lazy is a delegated property built on a lambda that computes the value on first access and caches it thereafter; it works on val properties and is thread-safe by default (SYNCHRONIZED mode), making it the natural choice for expensive one-time computations.

🏏

Cricket analogy: Like a stadium announcing 'Player of the Match' as lateinit, the slot exists but stays empty until the match ends, and asking too early throws an error, versus the ground's lazy pitch report that's computed once on first request and cached for the rest of the day.

How do companion objects compare to Java's static members?

Kotlin has no 'static' keyword. Instead, a class can declare a companion object, which is a real singleton object tied to the class that can hold properties/functions callable without an instance (ClassName.member). Unlike Java statics, a companion object is an actual object — it can implement interfaces, have an instance passed around, and be extended with extension functions — giving you static-like access with more flexibility.

🏏

Cricket analogy: Like a franchise's official 'League Office' that isn't a player but is a real organizational entity you can address directly (LeagueOffice.announceRules()), Kotlin's companion object is an actual singleton tied to the class, unlike Java's static keyword, and it can implement interfaces too.

What is the difference between == and ===?

== calls the structural equals() function (checking value/content equality, with null-safety built in), which is roughly equivalent to Java's .equals(). === checks referential equality — whether both operands point to the exact same object in memory, equivalent to Java's ==. For data classes, == uses the generated equals() and compares property values, while === would only be true if both variables reference the identical instance.

🏏

Cricket analogy: Like comparing two players by their stats (==, structural, same runs and average counts as equal) versus checking if they're literally the same person walking onto the field (===, referential); two data-class Player objects with identical stats are == even if they're different instances.

kotlin
data class Point(val x: Int, val y: Int)
val a = Point(1, 2)
val b = Point(1, 2)
println(a == b)   // true  — same property values
println(a === b)  // false — different objects in memory

How do coroutines differ from using threads directly?

A coroutine is a lightweight, suspendable unit of work managed by the Kotlin runtime, not the OS — thousands can run concurrently on a small pool of real threads because a suspended coroutine doesn't block its underlying thread, it simply yields it back. Threads are OS-level constructs that are comparatively expensive to create and always occupy their own stack while blocked. Coroutines use structured concurrency (scopes, jobs) to make cancellation and error propagation predictable, whereas raw thread management requires manual bookkeeping.

🏏

Cricket analogy: Like thousands of net-practice sessions sharing a handful of actual bowling machines by yielding turns rather than each session owning a dedicated machine, coroutines are lightweight and managed by the runtime, unlike OS threads which are expensive and each hold their own resources even while idle; structured concurrency (scopes, jobs) makes canceling a rained-out session predictable, unlike manually tracking every net session yourself.

What is the difference between primary and secondary constructors?

The primary constructor is declared in the class header (class User(val name: String, val age: Int)) and is the main entry point for initialization, often paired with init blocks. Secondary constructors are declared inside the class body with the constructor keyword and must delegate to the primary constructor (directly or transitively) via this(...) if a primary constructor exists. Secondary constructors are typically used to offer alternate ways to construct an object, such as for Java interop or overloaded construction patterns.

🏏

Cricket analogy: Like a player's core registration form (primary constructor: class Player(val name: String, val age: Int)) filled out once at signing, with alternate registration paths (secondary constructors) for transferred players that must still route through the same core form via this(...).

What is a smart cast?

After the compiler proves a nullable or supertype variable satisfies a check — such as an is check or a null comparison — it automatically treats the variable as the narrower, non-null type for the rest of that scope, without requiring an explicit cast. For example, inside if (obj is String) { obj.length } the compiler knows obj is a String and lets you call String members directly. Smart casts only work on val variables (or vars the compiler can prove aren't modified between the check and the use), because a mutable var could theoretically change type in between.

🏏

Cricket analogy: Like an umpire who, once confirming a delivery is a no-ball, automatically treats every subsequent call in that phase as a no-ball without re-checking, Kotlin's smart cast narrows obj to String inside if (obj is String) { obj.length }, but only for a val the compiler can prove won't change.

Quick Reference

  • val = read-only reference, var = mutable reference; neither implies deep immutability of the object.
  • Nullable types end in ? (String?); the compiler enforces null checks before dereferencing.
  • ?. short-circuits to null; ?: supplies a fallback; !! throws NPE — reserve !! for provably safe cases.
  • data class auto-generates equals/hashCode/toString/copy/componentN; requires at least one constructor parameter.
  • sealed class subtypes can differ in shape; enum entries share the same shape.
  • Extension functions are resolved statically at compile time, based on the declared type.
  • lateinit is for vars initialized later; lazy is for vals computed once on first access.
  • Companion objects replace Java statics but are real singleton objects that can implement interfaces.
  • == is structural equality (equals()); === is referential equality (same instance).
  • Coroutines are lightweight and cooperatively scheduled; suspending doesn't block the underlying thread.
  • Secondary constructors must delegate to the primary constructor via this(...).
  • Smart casts require the compiler to prove the type/nullability can't change between check and use.

Key Takeaways

  • Kotlin's null safety is enforced by the type system itself, catching NPEs at compile time instead of runtime.
  • Data classes and sealed classes eliminate huge amounts of Java boilerplate for value holders and closed hierarchies.
  • Extension functions add API surface without inheritance, but are statically dispatched — know the limits.
  • lateinit and lazy solve different deferred-initialization problems; don't conflate them.
  • Coroutines are a scheduling model built on lightweight suspension, not a replacement abstraction over raw OS threads.

Practice what you learned

Was this page helpful?

Topics covered

#Kotlin#KotlinProgrammingStudyNotes#Programming#CommonKotlinInterviewQuestions#Common#Interview#Questions#Frequently#StudyNotes#SkillVeris

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse