Bird
0
0

Why does Kotlin allow modifying the contents of a val mutable object but not reassigning the variable itself?

hard📝 Conceptual Q10 of 15
Kotlin - Variables and Type System
Why does Kotlin allow modifying the contents of a val mutable object but not reassigning the variable itself?
ABecause <code>val</code> variables are always primitive types
BBecause <code>val</code> fixes the reference, not the object's internal state
CBecause Kotlin does not support mutable objects
DBecause <code>val</code> makes both reference and object immutable
Step-by-Step Solution
Solution:
  1. Step 1: Understand val semantics

    val means the variable reference cannot change after assignment.
  2. Step 2: Distinguish reference and object mutability

    The object itself can be mutable, allowing internal changes.
  3. Final Answer:

    Because val fixes the reference, not the object's internal state -> Option B
  4. Quick Check:

    val fixes reference only [OK]
Quick Trick: val locks reference, not object state [OK]
Common Mistakes:
MISTAKES
  • Thinking val makes object immutable
  • Confusing reference and object
  • Assuming val only for primitives

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes