Kotlin Fundamentals Practice (Interactive)
Kotlin — Fundamentals Practice
10 auto-graded practice problems covering Kotlin fundamentals. Select an answer, submit, and review the explanation.
Null Safety
Coroutines
Scope Functions
Sealed Classes
Extension Functions
Delegation
Type System
Collections
Inline and Reified
Intuition
Kotlin combines object-oriented and functional programming: You can write imperative code with classes and objects or functional code with lambdas and higher-order functions. The language encourages immutable data and expressive, concise syntax.
Why it matters: Kotlin’s modern features (null safety, smart casts, extension functions) make it more productive than Java for most use cases.
The key insight: val vs var is not just about mutability, preferring val makes code easier to reason about and test because you know values will not change.
Common Mistakes
Confusing val and var: val declares an immutable reference (read-only after assignment). var declares a mutable reference. Prefer val everywhere possible, immutable code is easier to reason about and thread-safe by default.
Forgetting that Kotlin nulls are explicit: String? can hold null; String cannot. Forgetting the ? means the variable cannot be null, and assigning null to it is a compile error. Use ?. (safe call) and ?: (Elvis operator) to handle nullable types.
Misunderstanding data class equality: Data classes implement equals() based on structural equality (property values). Two data class instances with the same properties are equal. Regular classes use referential equality (== compares references).
Cross-References
- Site Home: Main landing page for kotlin notes.
- Practice: Practice problems for revision.
Detailed Content
Core Concepts
Worked Examples
Common Mistakes
- Rushing through foundational material
- Not practising problems after reading
- Failing to connect concepts across topics