Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Operators and Expressions
What will be the output of this Kotlin code?
val x = "Kotlin"
val y = "Kotlin"
println(x == y)
println(x === y)
Afalse true
Btrue true
Ctrue false
Dfalse false
Step-by-Step Solution
Solution:
  1. Step 1: Understand string literals and equality

    Both x and y are string literals with the same content. Kotlin interns string literals, so they point to the same object.
  2. Step 2: Evaluate == and === results

    x == y is true because content is the same. x === y is also true because both refer to the same interned string object.
  3. Final Answer:

    Output is true then true -> Option B
  4. Quick Check:

    String literals share reference, so both true [OK]
Quick Trick: String literals often share references, so === can be true [OK]
Common Mistakes:
MISTAKES
  • Assuming === is false for equal strings
  • Confusing == and === results
  • Ignoring string interning behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes