-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathX_Enums.java
More file actions
37 lines (35 loc) · 1.03 KB
/
X_Enums.java
File metadata and controls
37 lines (35 loc) · 1.03 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
/**
* An Enum is a special type used to define collections of constants. Basically,
* Enums define variables that represent members of a fixed set.
*/
public class X_Enums {
enum Rank {
SOLDIER, SERGEANT, CAPTAIN
}
public static void main(String[] args) {
Rank a = Rank.SOLDIER;
switch (a) {
case SOLDIER:
System.out.println("Soldier says hi!");
break;
case SERGEANT:
System.out.println("Sergeant says Hello!");
break;
case CAPTAIN:
System.out.println("Captain says Welcome!");
break;
}
a = Rank.SERGEANT;
switch (a) {
case SOLDIER:
System.out.println("Soldier says hi!");
break;
case SERGEANT:
System.out.println("Sergeant says Hello!");
break;
case CAPTAIN:
System.out.println("Captain says Welcome!");
break;
}
}
}