Bird
0
0

Find the error in this Kotlin code:

medium📝 Debug Q7 of 15
Kotlin - Variables and Type System
Find the error in this Kotlin code:
var message: String
message = 123
AMissing explicit type declaration
BVariable must be declared with val
CNo error, code is valid
DCannot assign Int to String variable
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type and assigned value

    The variable message is declared as String, but assigned an integer 123.
  2. Step 2: Identify type incompatibility

    Kotlin does not allow assigning an integer to a string variable, causing a type error.
  3. Final Answer:

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

    Explicit type must match assigned value type [OK]
Quick Trick: Assign values matching variable's declared type [OK]
Common Mistakes:
MISTAKES
  • Assigning wrong type values
  • Confusing var and val usage
  • Omitting type declaration (not error here)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes