ICSE Class 10 Computer Applications Question 7 of 16

Library Classes — Question 7

Back to all questions
7
Question

Question 5

Explain the terms, Autoboxing and Auto-unboxing in Java.

Answer

The automatic conversion of primitive data type into an object of its equivalent wrapper class is known as Autoboxing. For example, the below statement shows the conversion of an int to an Integer.

Integer a = 20;

Here, the int value 20 is autoboxed into the wrapper class Integer variable myinteger.

Auto-unboxing is the reverse process of Autoboxing. It is the automatic conversion of a wrapper class object­ into its corresponding primitive type. For example,

Integer myinteger = 20;   
int myint = myinteger;

Here, the object myInteger is automatically unboxed into primitive type int variable myint when the assignment takes place.