Bird
0
0

Which Kotlin expression correctly uses the safe call operator to get the length of a nullable string text?

easy📝 Conceptual Q2 of 15
Kotlin - Null Safety
Which Kotlin expression correctly uses the safe call operator to get the length of a nullable string text?
Atext?.length()
Btext.length?
Ctext?.length
Dtext.length
Step-by-Step Solution
Solution:
  1. Step 1: Identify safe call syntax

    The safe call operator is ?. placed before the member access.
  2. Step 2: Check each option

    text?.length uses text?.length which is correct syntax.
    text.length? has the operator after the property which is invalid.
    text?.length() treats length as a function which it is not.
    text.length accesses length without safe call, unsafe for nullable.
  3. Final Answer:

    text?.length -> Option C
  4. Quick Check:

    Safe call operator is ?. before property [OK]
Quick Trick: Safe call operator goes before property or method [OK]
Common Mistakes:
MISTAKES
  • Placing ? after the property name
  • Using parentheses with properties
  • Ignoring null safety on nullable types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes