Sunday, July 9, 2023

WRAPPER CLASS-AUTOBOX UNBOX

 wrapper class:

Primitive Type Wrapper class

boolean                    Boolean

char                    Character

byte                            Byte

short                    Short

int                            Integer

long                            Long

float                    Float

double                    Double



Autoboxing

The automatic conversion of primitive data type into its corresponding wrapper class is known as autoboxing, for example, byte to Byte, char to Character, int to Integer, long to Long, float to Float, boolean to Boolean, double to Double, and short to Short.


class BoxingExample1{  

  public static void main(String args[]){  

    int a=50;  

        Integer a2=new Integer(a);//Boxing    

        Integer a3=5;//Boxing            

        System.out.println(a2+" "+a3);  

 }   

}  

The automatic conversion of wrapper class type into corresponding primitive type, is known as Unboxing.

Unboxing

class UnboxingExample1{  

  public static void main(String args[]){  

    Integer i=new Integer(50);  

        int a=i;            

        System.out.println(a);  

 }   

}  


No comments:

Post a Comment