Auto Boxing And Un-Boxing

What is Auto Boxing?

Two type of Auto Boxing available in Java [Store value in Wrapper Class]

  1. Integer a1 = new Integer(50);
  2. Integer a2 = 60;

 

 

What is Auto-UnBoxing?

One type of Auto-UnBoxing available in Java [Store value in primitive data types using Wrapper Class]

  1. Integer a1 = new Integer(50);

int x = a1;     // Auto-unboxing

 

 

Let’s see example on boxing topic

 

class boxing1

{

                public static void main(String args[])

                {

                                // Auto – Boxing

                                Integer a1 = new Integer(20);    // Auto-Boxing 1

 

                                Integer a2 = 56;                                 // Auto-Boxing 2

                                System.out.println(“A1 = ” + a1);

                                System.out.println(“A2 = ” + a2);

 

 

// Auto – UnBoxing

                                Integer obj = new Integer(89);

                                int x = obj; // Auto – Unboxing

                                System.out.println(“X = ” + x);

                }

}

Output:

A1 = 20

A2 = 56

X = 89


Video available on YouTube.

 

 


If you have any query on blog example, you can directly comment us or subscribe our website

Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

177total visits,0visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

EmailEmail
PrintPrint