Bird
0
0

You want to keep track of a user's score that changes during the game. Which Kotlin declaration is best suited for this?

hard📝 Application Q8 of 15
Kotlin - Variables and Type System
You want to keep track of a user's score that changes during the game. Which Kotlin declaration is best suited for this?
1) val score = 0
2) var score = 0
3) const val score = 0
4) val var score = 0
A1 only
B2 only
C3 only
D4 only
Step-by-Step Solution
Solution:
  1. Step 1: Understand mutability needs

    The score changes during the game, so it must be mutable.
  2. Step 2: Evaluate each declaration

    1) uses val (immutable), 2) uses var (mutable), 3) uses const val (compile-time constant), 4) is invalid syntax.
  3. Final Answer:

    2 only -> Option B
  4. Quick Check:

    Mutable variable for changing score = A [OK]
Quick Trick: Use var for values that change over time [OK]
Common Mistakes:
MISTAKES
  • Choosing val for changing values
  • Using const val incorrectly
  • Writing invalid syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes