Bird
0
0

Find the error in this Kotlin code snippet:

medium📝 Debug Q7 of 15
Kotlin - Variables and Type System
Find the error in this Kotlin code snippet:
val number: Int
number = 5
number = 10
ACannot reassign a val variable after initialization
BVariable number is not declared
CMissing type declaration
DNo error, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Declaration without initialization

    val variables must be initialized once and cannot be reassigned.
  2. Step 2: Reassignment causes error

    Assigning 10 after assigning 5 is illegal for val.
  3. Final Answer:

    Cannot reassign a val variable after initialization -> Option A
  4. Quick Check:

    val reassignment forbidden [OK]
Quick Trick: val can be assigned once only [OK]
Common Mistakes:
MISTAKES
  • Thinking val can be reassigned
  • Ignoring initialization rules
  • Confusing var and val

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes