Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Variables and Type System
What will be the output of this Kotlin code?
var x = 3
x = x + 4
println(x)
A34
B3
CError
D7
Step-by-Step Solution
Solution:
  1. Step 1: Trace variable assignment and update

    Initially, x is 3. Then x = x + 4 updates x to 3 + 4 = 7.
  2. Step 2: Determine printed output

    The println(x) prints the current value of x, which is 7.
  3. Final Answer:

    7 -> Option D
  4. Quick Check:

    Variable update output = C [OK]
Quick Trick: var lets you change value; output reflects latest value [OK]
Common Mistakes:
MISTAKES
  • Thinking x remains 3 after reassignment
  • Concatenating numbers as strings
  • Expecting a syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes