Vidyalelo
Computer Science · Q251

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 251

Q251

You pass an integer to a function expecting type Any. It works without issue. Why is a primitive integer able to work with a function that expects an object? fun showHashCode(obj: Any) println(" obj.hasCode()") fun main() showHashCode(1)

A.
While the code runs, it does not produce correct results
B.
The integer is always a class
C.
The compiler runs an implicit .toClass() method on the integer
D.
The integer is autoboxed to a Kotlin Int class
Answer

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board