Bird
0
0

Find the issue in this Kotlin snippet:

medium📝 Debug Q7 of 15
Kotlin - Null Safety
Find the issue in this Kotlin snippet:
var age: Int = 25
age = null
AVariable age is immutable
BCode is correct
CMissing type declaration
DCannot assign null to non-nullable Int
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable mutability and type

    age is mutable var of non-nullable type Int.
  2. Step 2: Check assignment of null

    Assigning null to non-nullable Int is not allowed and causes compilation error.
  3. Final Answer:

    Cannot assign null to non-nullable Int -> Option D
  4. Quick Check:

    Non-nullable Int cannot be null [OK]
Quick Trick: Non-nullable Int rejects null even if mutable [OK]
Common Mistakes:
MISTAKES
  • Confusing mutability with nullability
  • Assuming null assignment is allowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes