Bird
0
0

Which of the following is the correct syntax to use the Elvis operator in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Null Safety
Which of the following is the correct syntax to use the Elvis operator in Kotlin?
Aval result = value ??: defaultValue
Bval result = value ? defaultValue
Cval result = value ?: defaultValue
Dval result = value ?:? defaultValue
Step-by-Step Solution
Solution:
  1. Step 1: Recall the correct Elvis operator syntax

    The Elvis operator is written as ?: without any extra characters or spaces.
  2. Step 2: Match the syntax with options

    val result = value ?: defaultValue uses ?: correctly between the variable and the default value.
  3. Final Answer:

    val result = value ?: defaultValue -> Option C
  4. Quick Check:

    Correct Elvis syntax = value ?: defaultValue [OK]
Quick Trick: Elvis operator is ?: exactly, no extra symbols [OK]
Common Mistakes:
MISTAKES
  • Using single question mark instead of ?:
  • Adding extra question marks
  • Swapping the order of symbols

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes