Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Core Architecture, Basics & Control Flow

Q12: Consider the following statements regarding Autoboxing and Unboxing in Java:

1. Autoboxing is the automated process where the Java compiler implicitly converts a primitive data type into its corresponding wrapper class object (e.g., 'int' to 'Integer').
2. The Java Collection Framework, including structures like ArrayList, is designed to allow the direct storage of raw primitive types like 'int' without any wrapper conversion.
3. Unboxing occurs when a wrapper class object is automatically converted back into its raw primitive form by the compiler during standard arithmetic operations or assignments.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: B
🎯 Quick Answer:
The correct combination is 1 and 3. Statement 2 is incorrect because Java Collections (like ArrayList or HashMap) can only store Objects, making it strictly impossible to store raw primitives without utilizing their respective wrapper classes.
Concept Definition: Wrapper classes transform basic primitive data types into fully-fledged objects.
Autoboxing and Unboxing are the syntactic sugar provided by the compiler to translate between the two states seamlessly.
Structural Breakdown: The 8 primitive types map directly to 8 wrapper classes (byte to Byte, int to Integer, char to Character, boolean to Boolean, etc.). Historical/Related Context: Prior to Java 5 (released in 2004), developers had to manually convert primitives to add them to lists (e.g., list.add(Integer.valueOf(5))) and manually extract them (e.g., int x = list.get(0).intValue()). The introduction of Autoboxing automated this tedious boilerplate code.
Causal Reasoning: Because Java is fundamentally an Object-Oriented language, advanced data structures, generic types (\), and serialization APIs require objects to function.
Autoboxing bridges the gap between high-speed primitive math and high-level object manipulation, allowing developers to write cleaner, more intuitive code.