Bird
0
0

Find the problem in this Kotlin code snippet:

medium📝 Debug Q7 of 15
Kotlin - Variables and Type System
Find the problem in this Kotlin code snippet:
var message: String
message = 100
println(message)
AMissing var keyword
BCannot assign Int to String variable
CVariable message not initialized
Dprintln syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type declaration

    message is declared as String type.
  2. Step 2: Check assigned value type

    Assigning integer 100 to a String variable causes a type mismatch error.
  3. Final Answer:

    Cannot assign Int to String variable -> Option B
  4. Quick Check:

    Type mismatch = C [OK]
Quick Trick: Variable type must match assigned value type [OK]
Common Mistakes:
MISTAKES
  • Assigning wrong type to variable
  • Assuming Kotlin allows implicit type conversion
  • Ignoring type declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes