Quiz
Kotlin track quiz: 10 questions on syntax, nullability, classes, coroutines.
Kotlin — track quiz
EXAMPLE
// 10 questions. Pass: >= 7. // ===== Q1 ===== // Which is the default visibility in Kotlin? // A) private // B) public // C) internal // D) protected // ===== Q2 ===== // 'val' means: // A) Cannot reassign the BINDING; the object itself MAY be mutable // B) Cannot mutate the object // C) The variable is null // D) Compile-time constant // ===== Q3 ===== // 'a?.b ?: c' means: // A) If a is null return null else c // B) If a is null return c; else a.b unless null, then c // C) Always returns c // D) Compile error // ===== Q4 ===== // 'when' without a subject is equivalent to: // A) switch-case // B) if-else if-else chain // C) try-catch // D) for-loop // ===== Q5 ===== // data class generates: // A) equals, hashCode, toString, copy, componentN // B) only equals + hashCode // C) only constructor // D) none of the above // ===== Q6 ===== // What is a 'sealed' class? // A) Final, cannot be extended // B) Closed hierarchy known at compile time; useful for exhaustive when // C) Same as enum // D) Auto-generates a companion object // ===== Q7 ===== // 'suspend' on a function means: // A) It returns immediately // B) It can be paused + resumed; can only be called from a coroutine or another suspend // C) It runs on the UI thread // D) It blocks the thread // ===== Q8 ===== // 'launch' vs 'async' in coroutines: // A) launch is fire-and-forget; async returns Deferred<T> // B) async is fire-and-forget; launch returns Deferred<T> // C) They are the same // D) async cannot be cancelled // ===== Q9 ===== // Which scope should you AVOID in production code? // A) viewModelScope // B) lifecycleScope // C) GlobalScope // D) coroutineScope // ===== Q10 ===== // 'by lazy' creates: // A) An unsafe value // B) A val that is computed on first access; thread-safe by default // C) A static field // D) A const val // ===== Answers ===== // 1. B — public is default // 2. A — val locks the binding, not the object // 3. B — safe call + Elvis // 4. B — when without subject is if-else chain // 5. A — data class generates all of these // 6. B — sealed = closed hierarchy // 7. B — suspend functions are coroutine-aware // 8. A — launch fire-and-forget; async deferred // 9. C — GlobalScope leaks; use viewModelScope / lifecycleScope / structured scope // 10. B — by lazy is thread-safe by default // ===== Patterns to internalise ===== // - val by default; var only when truly mutable // - data class for value-shape types // - sealed for closed type hierarchies; pair with exhaustive when // - suspend + structured concurrency (NEVER GlobalScope in prod) // - 'by lazy' for expensive single-init values
Why it matters
Quiz takeaway: val + nullability + sealed hierarchies + structured coroutines are the Kotlin reflexes. GlobalScope is the most common production mistake; structured scopes (viewModelScope, lifecycleScope, coroutineScope) keep concurrency tidy. Master data class + sealed + when and your domain modelling sings.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…