Write a program to demonstrate the concept of boxing and unboxing


Write a program to demonstrate the concept of boxing and unboxing.

Program:

public class BoxUnbox 

{

   public static void main(String[] args)

    {

        //Boxing

        int a=34;

        Integer a1=a;

        Integer a2=50;

        System.out.println("Value after boxing: "+a1+" , "+a2);

        

        //Unboxing

        int b=a1;

        int c=a2;

        System.out.println("Value after unboxing: "+b+" , "+c);

    }

}


Output:

Value after boxing: 34 , 50

Value after unboxing: 34 , 50