Bird
0
0

Which of the following statements about val variables is TRUE?

easy📝 Conceptual Q2 of 15
Kotlin - Variables and Type System
Which of the following statements about val variables is TRUE?
A<code>val</code> variables cannot hold mutable objects
B<code>val</code> variables cannot be reassigned to a new object
C<code>val</code> variables can be reassigned multiple times
D<code>val</code> variables are always primitive types
Step-by-Step Solution
Solution:
  1. Step 1: Recall val behavior

    val means the reference cannot be changed after assignment.
  2. Step 2: Understand mutability of objects

    Even if the object is mutable, the val reference cannot point to a different object.
  3. Final Answer:

    val variables cannot be reassigned to a new object -> Option B
  4. Quick Check:

    val = no reassignment [OK]
Quick Trick: val locks reference, not object mutability [OK]
Common Mistakes:
MISTAKES
  • Assuming val forbids mutable objects
  • Thinking val allows reassignment
  • Confusing val with var

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes