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