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 variablevalโ 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
objectcompanion 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)whenforwhiledo-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
