Bird
0
0

What does the val keyword do in Kotlin?

easy📝 Conceptual Q11 of 15
Kotlin - Variables and Type System
What does the val keyword do in Kotlin?
ADefines a class
BCreates an immutable reference that cannot be reassigned
CDeclares a function
DCreates a mutable variable that can be reassigned
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of val

    val declares a variable whose reference cannot be changed after assignment.
  2. Step 2: Compare with other keywords

    var allows reassignment, but val does not.
  3. Final Answer:

    Creates an immutable reference that cannot be reassigned -> Option B
  4. Quick Check:

    val = immutable reference [OK]
Quick Trick: Remember: val means fixed reference, var means changeable [OK]
Common Mistakes:
MISTAKES
  • Confusing val with var
  • Thinking val makes the object itself immutable
  • Assuming val declares a function or class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes