Kotlin Fundamentals


1️⃣ Kotlin Fundamentals – Interview


1️⃣ What is Kotlin?

Answer:
Kotlin is a statically typed, JVM-based programming language developed by JetBrains. It is concise, null-safe, fully interoperable with Java, and supports both object-oriented and functional programming.


2️⃣ Is Kotlin statically typed?

Answer:
Yes. Kotlin is statically typed, meaning the type of a variable is checked at compile time, even when type inference is used.


3️⃣ Kotlin vs Java (Beginner Level)

Answer:

  • Less boilerplate
  • Built-in null safety
  • Data classes
  • Extension functions
  • Coroutines for async programming

4️⃣ What is var and val?

Answer:

  • var → mutable variable
  • val → read-only variable (cannot be reassigned)
var count = 10
val name = "Kotlin"

5️⃣ Is val a constant?

Answer:
❌ No.
val is read-only, not a compile-time constant.


6️⃣ What is const val?

Answer:
const val is a compile-time constant that is inlined at compile time.

const val MAX_LIMIT = 100

Allowed only at:

  • Top-level
  • object
  • companion object

7️⃣ What is type inference?

Answer:
Kotlin automatically infers the variable type based on the assigned value.

val x = 10  // Int inferred

8️⃣ What is the fun keyword?

Answer:
fun is used to declare a function in Kotlin.

fun add(a: Int, b: Int): Int {
    return a + b
}

9️⃣ Does Kotlin support default arguments?

Answer:
Yes.

fun greet(name: String = "Guest") {
    println("Hello $name")
}

🔟 What are string templates?

Answer:
They allow embedding variables or expressions inside strings.

val name = "Akshay"
println("Hello $name, length = ${name.length}")

1️⃣1️⃣ What control flow statements exist in Kotlin?

Answer:

  • if (expression)
  • when
  • for
  • while
  • do-while

1️⃣2️⃣ Difference between if in Java and Kotlin?

Answer:
In Kotlin, if is an expression and returns a value.

val max = if (a > b) a else b

1️⃣3️⃣ What is when?

Answer:
when is Kotlin’s replacement for switch, but more powerful.

when (x) {
    1 -> println("One")
    in 2..5 -> println("Range")
    else -> println("Other")
}

1️⃣4️⃣ What are ranges in Kotlin?

Answer:
Ranges represent a sequence of values.

1..5
1 until 5
5 downTo 1

1️⃣5️⃣ What are packages in Kotlin?

Answer:
Packages organize code and prevent naming conflicts.

package com.example.utils

1️⃣6️⃣ Does Kotlin support comments?

Answer:
Yes.

  • Single-line: //
  • Multi-line: /* */
  • Nested comments supported ✔

1️⃣7️⃣ Does Kotlin support top-level functions?

Answer:
Yes. Kotlin allows functions outside classes.

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

1️⃣8️⃣ What is main() in Kotlin?

Answer:
main() is the entry point of a Kotlin program.

fun main() {
    println("Hello World")
}

1️⃣9️⃣ Is Kotlin case-sensitive?

Answer:
Yes. Kotlin is case-sensitive.


2️⃣0️⃣ One-Line Beginner Summary (Interview Favorite)

Kotlin is a statically typed, null-safe, concise JVM language fully interoperable with Java.


✅ How to Use This

You can now:

  • Convert each question into MCQs
  • Create coding exercises
  • Make YouTube interview videos
  • Build PDF interview notes

Share with