98-372 · Question #33
98-372 Question #33: Real Exam Question with Answer & Explanation
The correct answer is C. int it = 12345;. Boxing is used to convert a value type to a reference type. In this sample code segment, the Integer object is a value type, and the instance of the Object class is a reference type. Converting from the value type to the reference type requires boxing. Boxing is an implicit conve
Question
Options
- Adouble dou = 12345;
- Bobject obj = 12345;
- Cint it = 12345;
- Dint it = 12345;
Explanation
Boxing is used to convert a value type to a reference type. In this sample code segment, the Integer object is a value type, and the instance of the Object class is a reference type. Converting from the value type to the reference type requires boxing. Boxing is an implicit conversion of a value type to a reference type. Consider the following declaration of a value type variable: The following statement implicitly applies the boxing operation on the variable test: object obj=test; This statement creates a reference to an object obj (on the stack) that references a value of the type int (on the heap). This value is a copy of the value-type value assigned to the variable test. It is not necessary to perform the boxing explicitly, as in the following example: object obj=(Object) test; Answer: A and D are incorrect. Converting between two value types requires neither boxing nor Answer: B is incorrect. Converting from a reference type to a value type is unboxing.
Community Discussion
No community discussion yet for this question.