Bird
0
0

What is wrong with this Kotlin code?

medium📝 Debug Q7 of 15
Kotlin - Data Types
What is wrong with this Kotlin code?
val ch: Char = 65
AChar can hold Int values directly
B65 is a valid Char literal
CCannot assign Int directly to Char without conversion
DCode compiles without error
Step-by-Step Solution
Solution:
  1. Step 1: Understand type assignment rules

    Kotlin does not allow assigning an Int directly to a Char variable.
  2. Step 2: Identify required conversion

    To assign 65 as a Char, you must convert it using 65.toChar().
  3. Final Answer:

    Cannot assign Int directly to Char without conversion -> Option C
  4. Quick Check:

    Int to Char needs explicit conversion [OK]
Quick Trick: Use toChar() to convert Int to Char explicitly [OK]
Common Mistakes:
MISTAKES
  • Assigning Int directly to Char
  • Assuming implicit conversion happens
  • Expecting code to compile without error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes