Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q6 of 15
Kotlin - Data Types
Identify the error in this Kotlin code snippet:
val ch: Char = "C"
AChar literals must use single quotes, not double quotes
BChar cannot be assigned directly
CMissing semicolon at the end
DDouble quotes are allowed for Char literals
Step-by-Step Solution
Solution:
  1. Step 1: Check Char literal syntax

    In Kotlin, Char literals require single quotes, double quotes create a String.
  2. Step 2: Identify the error

    Assigning "C" to a Char causes a type mismatch error.
  3. Final Answer:

    Char literals must use single quotes, not double quotes -> Option A
  4. Quick Check:

    Char literals need single quotes 'C' [OK]
Quick Trick: Use single quotes for Char, double quotes for String [OK]
Common Mistakes:
MISTAKES
  • Using double quotes for Char literals
  • Forgetting Kotlin does not require semicolons
  • Thinking Char can hold String values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes