Kotlin is statically typed like Java and C#. Use val for read-only references and var for mutable ones—both require explicit or inferred types.
Basic types
Int,Long,Double— numeric types (capitalized, not Java primitives in source)String— immutable UTF-16 textBoolean—trueorfalseChar— single UTF-16 code unit
val vs var
val count = 10 // read-only reference
var total = 0 // mutable
total += count
val does not make objects immutable—only the variable binding. Prefer val by default.
Important interview questions and answers
- Q: val vs var?
A:valassigns once (like final in Java);varallows reassignment. - Q: Are Kotlin types nullable by default?
A: No—Stringcannot hold null unless you writeString?.
Self-check
- Which keyword declares a read-only variable?
- Can you reassign a
val?
Pitfall: val does not make objects immutable—only the variable binding; prefer val by default.
Interview prep
- val vs var?
val assigns once; var allows reassignment.
- Nullable by default?
No—use String? for nullable references.