Monday, January 13, 2014

Java Wrapper class Example programs

//Note:  Analysis the programs errors,outputs and Understand the Wrapper class in Java



//[1]
class WrapperDemo1{
public static void main(String arg[])
{
//Wrapper class objects will convert to primitive types
Integer i=new Integer(75);
int ii=i.intValue();
System.out.println(ii);
float f=i.floatValue();
System.out.println(f);
}
}


//[2]
class WrapperDemo2{
public static void main(String... arg)
{
Integer i=Integer.parseInt(arg[2]);
int ii=i.intValue();
System.out.println(ii);
}
}



//[3]
class WrapperDemo2{
public static void main(String arg[])
{
//Wrapper class objects will be convert to primitive types through parameter passing
int i=75;
demo(i);//passing primitive
}
public static void demo(Integer i)//received by wrapper
{
System.out.println(i);
}
}

No comments: