Bird
0
0

Which Kotlin declaration correctly defines a non-nullable integer variable?

easy📝 Conceptual Q2 of 15
Kotlin - Null Safety
Which Kotlin declaration correctly defines a non-nullable integer variable?
Aval number = null
Bval number: Int = 10
Cval number: Int? = null
Dval number: Int? = 10
Step-by-Step Solution
Solution:
  1. Step 1: Identify non-nullable integer declaration

    Non-nullable types do not have ? and must be initialized with a non-null value.
  2. Step 2: Check each option

    val number: Int = 10 declares Int without ? and assigns 10, which is valid and non-null.
  3. Final Answer:

    val number: Int = 10 -> Option B
  4. Quick Check:

    Non-nullable Int = val number: Int = 10 [OK]
Quick Trick: Non-nullable types have no ? and need a value [OK]
Common Mistakes:
MISTAKES
  • Using ? for non-nullable
  • Assigning null to non-nullable variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes