Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Variables and Type System
Identify the error in this Kotlin code snippet:
val count: Int = 5
count = 10
AMissing type declaration for count
BVariable count should be declared with var
CIncorrect type Int assigned to count
DCannot reassign a value to val variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand val and var difference

    val means the variable is read-only and cannot be reassigned after initialization.
  2. Step 2: Check the reassignment

    The code tries to assign 10 to count which is declared as val, causing an error.
  3. Final Answer:

    Cannot reassign a value to val variable -> Option D
  4. Quick Check:

    val is fixed, reassignment causes error [OK]
Quick Trick: val variables cannot be reassigned [OK]
Common Mistakes:
MISTAKES
  • Thinking val variables can be changed
  • Confusing val and var keywords
  • Ignoring reassignment rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes