Bird
0
0

Which of the following is the correct syntax to safely call the length property of a nullable String name?

easy📝 Syntax Q12 of 15
Kotlin - Null Safety
Which of the following is the correct syntax to safely call the length property of a nullable String name?
Aval len = name.length
Bval len = name?.length
Cval len = name!!length
Dval len = name?length
Step-by-Step Solution
Solution:
  1. Step 1: Identify the safe call syntax

    The safe call operator is ?., used as object?.property or object?.function().
  2. Step 2: Check each option

    val len = name.length uses . without safety, which can cause a crash if name is null. val len = name?.length correctly uses ?.. val len = name!!length uses !! incorrectly with property access. val len = name?length uses invalid syntax ?length.
  3. Final Answer:

    val len = name?.length -> Option B
  4. Quick Check:

    Safe call syntax = ?. [OK]
Quick Trick: Safe call uses ?. between object and property [OK]
Common Mistakes:
MISTAKES
  • Using . without safe call on nullable
  • Confusing !! with ?.
  • Writing invalid syntax like ?property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes