Wrapper class is a mechanism to convert primitive type into object and object into primitive type.Wrapper classes available in java.lang package. There are eight wrapper classes are given below.
Wrapper class Primitive Type
1. Byte byte
2. Short short
3. Integer int
4. Long long
5. Float float
6. Double double
7. Character char
8. Boolean boolean
1. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class M1
{
public static void main(String[] args)
{
int i = 0;
Integer obj = new Integer(i);
int k = obj.intValue();
System.out.println("done");
}
}
2. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class M2
{
public static void main(String[] args)
{
Double d1 = new Double(10.09);
double d2 = d1.doubleValue();
System.out.println("done");
System.out.println(d2);
}
}
3. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class M3
{
public static void main(String[] args)
{
char c1 = 'a';
Character c2 = new Character(c1);
char c3 = c2.charValue();
System.out.println("done");
}
}
4. Program
//Find what it gives Compiletion Error / Compiletion Successfully / Output ?
class M4
{
public static void main(String[] args)
{
boolean b1 = false;
Boolean b2 = new Boolean(b1);
Boolean b3 = new Boolean(true);
boolean b4 = b2.booleanValue();
boolean b5 = b3.booleanValue();
System.out.println(b4 +" "+b5);
System.out.println("done");
}
}