Interviews2 answers
Different between Boxing and Unboxing?
2 Answers
In a simple word we can say that : Boxing is a process of converting the Value Type into Object Type
Example :-
Object obj;
int a =125;
obj=a;
While UnBoxing is a process of retrieving the origional type(Value Type) from the Object Type.
Example:-
a=(int)obj;
Praveen KumarPosted Sep 7, 2014, 11:12 PM EDT
1. Boxing
If at all a value type is assigned to a refernce type variable we call it as "Boxing"
Eg-
int i=99; //varialbe initialization
Object obj=i; //Assign variable to obj(i.e Boxing)
2. Unboxing
Converting reference type back into value type is known as "Unboxing"
Eg-
int j=(int)obj; //(unboxing)
Satheesh Kumar PilliPosted Aug 20, 2014, 9:56 AM EDT

