OOPS in JAVA 23
Wrapper class in Java
Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.
Since J2SE 5.0, (auto)boxing and unboxing feature converts primitive into object and object into primitive automatically. The automatic conversion of primitive into object is known and (auto)boxing and vice-versa unboxing.
One of the eight classes of java.lang package are known as wrapper class in java. The list of eight wrapper classes are given below.
boolean | Boolean |
char | Character |
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
Example of boxing and unboxing:
public class Test{public static void main(String args[]){
Integer x = 5; // boxes int to an Integer object
x = x + 10; // unboxes the Integer to a int
System.out.println(x);
}
}
Output:
15
No comments:
Post a Comment
Hai , Post your comment . (required, Bugs, Errors )