-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumDemo2.java
More file actions
41 lines (34 loc) · 1.13 KB
/
EnumDemo2.java
File metadata and controls
41 lines (34 loc) · 1.13 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
enum Transport {
CAR, TRUCK, AIRPLANE, TRAIN, BOAT
}
class EnumDemo2 {
public static void main(String args[]) {
Transport tp;
System.out.println("Values of Transport: ");
Transport allTransports[] = Transport.values();
for(Transport t : allTransports)
System.out.println(t);
System.out.println();
tp = Transport.valueOf("AIRPLANE");
System.out.println("tp equals to: " + tp);
if(tp == Transport.TRAIN)
System.out.println("tp equals to TRAIN\n");
switch(tp) {
case CAR:
System.out.println("CAR transfer people");
break;
case TRUCK:
System.out.println("TRUCK transfer cargo");
break;
case AIRPLANE:
System.out.println("AIRPLANE flys");
break;
case TRAIN:
System.out.println("TRAIN rides on rails");
break;
case BOAT:
System.out.println("BOAT floats on water");
break;
}
}
}