1.wrapper Classes
1.wrapper Classes
– Understand cloning
• For example, you can take the integer input from the user in
the form of a String, and convert it into integer type using the
following statements:
• String str = “100”;
• int j = Integer.parseInt(str);
• There are many more methods in the wrapper classes that
help you do several operations with the data types.
• The wrapper classes also have constants like :
• MAX_VALUE, MIN_VALUE, NaN (Not a Number),
POSITIVE_INFINITY, and NEGATIVE_INFINITY.
Object
int intValue( ) returns the value of the invoking object as a int value
long ln=999;
Long lng=new Long(ln);
Long ls=new Long("666");
System.out.println("long value="+lng.longValue());
System.out.println("long value from string
version="+ls.longValue());
Output:
long value=999
long value from string version=666
short s=9;
Short sh=new Short(ln);
Short ls=new Short(“6");
System.out.println("short value="+lng.shortValue());
System.out.println("short value from string
version="+ls.shortValue());
Output:
short value=999
short value from string version=666
Wrong!!! Wrong!!!
Right!!!
byte b = 12;
Integer I1=(int)b;
t.m1(l1); }}
24 © 2012 WIPRO LTD | WWW.WIPRO.COM | CONFIDENTIAL
Quiz
What is the output of the following code?
class Test {
static void fun(int i) {
System.out.println("int");
}
XYZ cloneTest() {
try {
return (XYZ) super.clone();
} catch (CloneNotSupportedException e) {
System.out.println("Cloning Not Allowed");
return this;
}
}
}