Bird
0
0

Which of the following Kotlin statements correctly uses the safe cast operator as??

easy📝 Syntax Q3 of 15
Kotlin - Null Safety

Which of the following Kotlin statements correctly uses the safe cast operator as??

Aval s = obj as String?
Bval s = obj as? String
Cval s = obj as ? String
Dval s = obj as ?String
Step-by-Step Solution
Solution:
  1. Step 1: Review correct safe cast syntax

    The safe cast operator is as? without spaces between as and ?.
  2. Step 2: Identify correct spacing and usage

    val s = obj as? String uses correct syntax with no spaces and proper nullable type.
  3. Final Answer:

    val s = obj as? String -> Option B
  4. Quick Check:

    Safe cast syntax is as? without spaces = D [OK]
Quick Trick: Safe cast operator is 'as?' with no spaces [OK]
Common Mistakes:
MISTAKES
  • Adding spaces between 'as' and '?'
  • Using unsafe cast syntax with '?'
  • Confusing nullable type syntax with safe cast

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes