Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Data Types
What will be the output of this Kotlin code?
val x: Any = 42
println(x.toString())
AAny@<hashcode>
B42
CCompilation error
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable type and value

    Variable x is of type Any holding integer 42.
  2. Step 2: Call toString() on Int stored as Any

    Calling toString() on an Int returns its string representation "42".
  3. Final Answer:

    The output will be "42". -> Option B
  4. Quick Check:

    Any holds Int, toString() returns "42" [OK]
Quick Trick: toString() on Any returns actual object's string [OK]
Common Mistakes:
MISTAKES
  • Expecting default Any toString output
  • Confusing type with value representation
  • Thinking it causes compilation error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes