Boxing is a process of conversion of a value to generic object type for example
Consider the following code
Int alpha=1;
object boxed_alpha= alpha;
This conversion to generic type is called as boxing
Unboxing is the reverse of a boxing continuing with the above example let us unbox boxed_alpha as a string
String string_alpha=(String) boxed_alpha;
OR
String string_alpha=boxed_alpha.ToString();
I will discuss its use subsequent comments
Even if we convert a class type to an interface type it comes under boxing for example
ReplyDeleteInterface vehicles
{
string wheeltypes();
string steeringtype();
}
class car implements vehicles
{
public string wheeltypes()
{
}
public string steeringtype()
{
}
}
public static void main()
{
car Maruti=new vehicles();
}
In my last comment
ReplyDeletecar Maruti =new vehicles();
is a process of boxing