Bird
0
0

What does adding a ? after a type in Kotlin mean?

easy📝 Conceptual Q11 of 15
Kotlin - Null Safety
What does adding a ? after a type in Kotlin mean?
AThe variable is immutable.
BThe variable can hold a null value.
CThe variable is a constant.
DThe variable is a function.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin type suffix

    In Kotlin, adding ? after a type means the variable can hold null.
  2. Step 2: Compare with non-nullable types

    Without ?, variables cannot be null and will cause errors if assigned null.
  3. Final Answer:

    The variable can hold a null value. -> Option B
  4. Quick Check:

    Nullable type = variable can be null [OK]
Quick Trick: Remember: ? means nullable type in Kotlin [OK]
Common Mistakes:
MISTAKES
  • Thinking ? makes variable immutable
  • Confusing ? with constant declaration
  • Assuming ? means function type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes