DifferenceModerate2 marks
Differentiate between boxing and unboxing.
Topic: Boxing and unboxing
Previous-year question practice database
Answer
Exam answer
The difference is shown in the table.
Explanation
Both terms describe conversion between the two worlds of Java data: primitives (int, char, double) and objects (Integer, Character, Double). Boxing wraps a primitive inside an object; unboxing unwraps it again. The direction is all that distinguishes them, so name the direction explicitly in your answer and give one example of each. Modern Java does both automatically where the context makes the intention clear — Integer n = 25; is autoboxing and int m = n; is auto-unboxing. Mentioning autoboxing shows fuller understanding.
Comparison
| Boxing | Unboxing |
|---|---|
| Converting a primitive data type into an object of its corresponding wrapper class. | Converting a wrapper class object back into its primitive data type. |
| Example: Integer n = Integer.valueOf(25); | Example: int m = n.intValue(); |
More from Library Classes
What is the output of the statement Math.pow(36, 6/5);?2026The output of the statement:
System.out.println(Character.toUpperCase('b') + 2); is:2026What is the type of parameter to be given for the method parseInt()?2026Write the Java expression to find the sum of cube root of x and the absolute value of y.2026Character class methods are found in the package called:2025The output of Math.max(-7, Math.min(-5, -4)) is2025