Bird
0
0

Identify the error in this Kotlin code:

medium📝 Debug Q6 of 15
Kotlin - Variables and Type System
Identify the error in this Kotlin code:
val age = 30
println("Age is $age years old")
AMissing plus operator for concatenation
BIncorrect use of $ for variable
CMissing curly braces around age
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check variable interpolation syntax

    Using $age inside a string is correct for simple variables without needing curly braces.
  2. Step 2: Verify string concatenation

    String templates handle concatenation automatically, so no plus operator is needed.
  3. Final Answer:

    No error, code is correct -> Option D
  4. Quick Check:

    Simple variables can use $variable without braces [OK]
Quick Trick: Use $variable for simple variables, ${} for expressions [OK]
Common Mistakes:
MISTAKES
  • Adding unnecessary curly braces
  • Trying to concatenate with + inside templates
  • Thinking $variable needs quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes