-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_wrapper_class.java
More file actions
23 lines (20 loc) · 985 Bytes
/
Copy pathOOP_wrapper_class.java
File metadata and controls
23 lines (20 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
public class OOP_wrapper_class
{
/* Wrapper class: A class that contains/wraps primitive dataypes. When we create a wrapper class, it contains fields and in this fields we can
store primitive data types.
Autoboxing: The process of converting a primitive datatype to a wrapper class object.
Unboxing: Getting the value of a wrapper class object and storing it into a primitive type variable.
*/
public static void main(String[] args)
{
Integer i = new Integer(5); // Integer: wrapper class
int num = 4; // int: primitive datatype
Integer i2 = new Integer(num); // Autoboxing
int i3 = i2.intValue(); // Unboxing
System.out.println(num); // prints 4
System.out.println(i); // prints 4
System.out.println(i2); // prints 5
System.out.println(i3); // prints 4
}
}