ICSE Class 10 Computer Applications Question 11 of 16

Using Library Classes — Question 13

Back to all questions
13
Question

Question 13

What important is automatically happening in following code ?

long a = 124235L; 
Long b = new Long(a);
long c = b.longValue(); 
System.out.println(c);
Answer

Long b = new Long(a);

This statement boxes long type a into a Long object b, boxing a primitive type into a Wrapper class object.

long c = b.longValue();

This statement unboxes Long object b and stores it in long variable c, converting a Wrapper class object into a primitive data type.