Bird
0
0

In Kotlin, what does it mean when a variable type is declared without a ? at the end?

easy📝 Conceptual Q1 of 15
Kotlin - Null Safety
In Kotlin, what does it mean when a variable type is declared without a ? at the end?
AThe variable can hold null values.
BThe variable cannot hold null values.
CThe variable is mutable.
DThe variable is a constant.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin type declaration

    In Kotlin, types without ? are non-nullable by default, meaning they cannot hold null.
  2. Step 2: Interpret the meaning of no ?

    Since the type is non-nullable, the variable must always hold a non-null value.
  3. Final Answer:

    The variable cannot hold null values. -> Option B
  4. Quick Check:

    Non-nullable type = Cannot hold null [OK]
Quick Trick: No ? means no null allowed [OK]
Common Mistakes:
MISTAKES
  • Thinking variables without ? can hold null
  • Confusing mutability with nullability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes