-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion40.java
More file actions
31 lines (30 loc) · 1.09 KB
/
Question40.java
File metadata and controls
31 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// program to demonstrate concept of wrapper class
class Question40 {
public static void main(String[] args) {
// variables of primitive data type
byte test_byte = 2;
int test_int = 34;
float test_float = (float) 3.14;
double test_double = 50.11446534;
// using wrapper classes to create a wrapped object
Byte b = new Byte (test_byte);
Integer i = new Integer (test_int);
Float f = new Float (test_float);
Double d = new Double (test_double);
System.out.println ("Printing the wrapped objects: ");
System.out.println ("Byte Object b: " + b);
System.out.println ("Integer Object i: " + i);
System.out.println ("Float Object f: " + f);
System.out.println ("Double Object d: " + d);
// getting value of the wrapped objects
byte b2 = b.byteValue ();
int i2 = i.intValue();
float f2 = f.floatValue ();
double d2 = d.doubleValue ();
System.out.println ("Printing values of the wrapped objects: ");
System.out.println ("Value of b2: " + b2);
System.out.println ("Value of i2: " + i2);
System.out.println ("Value of f2: " + f2);
System.out.println ("Value of d2: " + d2);
}
}