DefinitionModerate2 marks
What is autoboxing in Java? Give an example.
Topic: Autoboxing
Previous-year question practice database
Answer
Exam answer
Autoboxing is the automatic conversion by the Java compiler of a primitive data type into an object of its corresponding wrapper class, without the programmer writing any conversion code.
Example: Integer n = 25; Here the primitive int value 25 is automatically wrapped into an Integer object.
Explanation
The key word is AUTOMATIC — boxing done explicitly, as in Integer n = Integer.valueOf(25);, is just boxing; autoboxing is when Java does it silently because the context requires an object. The reverse process is auto-unboxing: int m = n; where the Integer object is unwrapped back into a primitive. Always give the one-line example — a definition alone rarely earns both marks.
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