Bird
0
0

Which of the following is the correct syntax to declare a nullable String variable in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Null Safety
Which of the following is the correct syntax to declare a nullable String variable in Kotlin?
Avar name: String?
Bvar name: ?String
Cvar name: String!
Dvar name: nullable String
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin nullable syntax

    Kotlin uses ? after the type name to mark it nullable, e.g., String?.
  2. Step 2: Check each option

    var name: String? uses String? correctly. Options A, B, and D use invalid syntax.
  3. Final Answer:

    var name: String? -> Option A
  4. Quick Check:

    Nullable syntax = type followed by ? [OK]
Quick Trick: Put ? right after the type name for nullable [OK]
Common Mistakes:
MISTAKES
  • Placing ? before the type
  • Using ! instead of ?
  • Writing 'nullable' keyword explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes