C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers


10,705 users

Differentiate between Boxing and Unboxing?

0 votes
asked by keem Expert (13,240 points)

2 Answers

0 votes
When a value type is converted to an object type, the process is known as boxing; whereas, when an object type is converted to a value type, the process is known as unboxing. 
Boxing and unboxing enable value types to be treated as objects. Boxing a value type packages it inside an instance of the Object reference type. This allows the value type to be stored on the garbage collected heap. Unboxing extracts the value type from the object. In this example, the integer variable i is boxed and assigned to object obj.
int i = 123;
object obj = i; /* Thi line boxes i. */ 
/* The object obj can then be unboxed and assigned to integer variable i: */
i = (int)obj; // unboxing 
answered by sara Guru (24,570 points)
0 votes
Implicit (manual) conversion of value type to reference type of a variable is known as BOXING, for example integer to object type conversion. Conversion of Boxed type variable back to value type is called as UnBoxing.
answered by smith Geek (15,340 points)

Related questions

0 votes
1 answer 20 views
0 votes
1 answer 60 views
0 votes
2 answers 8 views
0 votes
3 answers 175 views
175 views asked by daniel Advisor (5,600 points)
0 votes
1 answer 12 views