-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTypePromotion.java
More file actions
58 lines (48 loc) · 1.22 KB
/
TypePromotion.java
File metadata and controls
58 lines (48 loc) · 1.22 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class TypePromotion {
void show(byte x) {
System.out.println("Byte X");
}
void show(short x) {
System.out.println("Short X");
}
// void show(int x) {
// System.out.println("Int X");
// }
// void show(long x) {
// System.out.println("Long X");
// }
// void show(float x) {
// System.out.println("Float X");
// }
// void show(Integer x) {
// System.out.println("Integer Wrapper X");
// }
// void show(Float x) {
// System.out.println("Float Wrapper X");
// }
void show(int ...x) {
System.out.println("Int Var Args X");
}
public static void main(String[] args) {
TypePromotion obj = new TypePromotion();
// will execute int first
// if int is not available then it goes for
// type promotion and will execute long
// Type widening - will execute float if long
// is not available
// obj.show(20);
// obj.show(4,5,6,8,1);
obj.show((byte)6); // now it will call byte
obj.show((short)10); // now it will call short
//Autoboxing - Boxing and Unboxing
Integer i = 12;
int i1 = i;
//Integer i2 = new Integer(i1); // deprecated
byte x = 127;
x += 1;
x++;
System.out.println(x++);
//int x1 = x;
//byte x2 = x1;
}
}