Bird
0
0

Which of the following Kotlin declarations correctly creates an immutable variable?

easy📝 Syntax Q12 of 15
Kotlin - Variables and Type System
Which of the following Kotlin declarations correctly creates an immutable variable?
Avar name = "Alice"
Bval name = "Alice"
Cimmutable name = "Alice"
Dconst var name = "Alice"
Step-by-Step Solution
Solution:
  1. Step 1: Identify Kotlin syntax for immutable variables

    Kotlin uses val to declare immutable variables that cannot be reassigned.
  2. Step 2: Check each option

    val name = "Alice" uses val correctly. var name = "Alice" uses var which is mutable. The other two options use invalid syntax.
  3. Final Answer:

    val name = "Alice" -> Option B
  4. Quick Check:

    Immutable variable syntax = val [OK]
Quick Trick: val means immutable, var means mutable [OK]
Common Mistakes:
MISTAKES
  • Using var instead of val for immutability
  • Trying to use 'immutable' keyword
  • Combining const and var incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes