-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumExample.java
More file actions
47 lines (36 loc) · 948 Bytes
/
EnumExample.java
File metadata and controls
47 lines (36 loc) · 948 Bytes
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
package java;
public class EnumExample {
public static void main(String[] args) {
Coin flip = Coin.TAILS;
switch (flip) {
case HEADS:
System.out.println("heads!");
break;
case TAILS:
System.out.println("tails!");
break;
default:
System.out.println("an error occured...");
break;
}
CryptoPeople[] people = CryptoPeople.values();
for (CryptoPeople p: people) {
System.out.println(p + " is " + p.getDescription());
}
}
enum Coin {
HEADS, TAILS;
}
}
enum CryptoPeople {
ALICE("great"),
BOB("nice"),
EVE("evil");
private String description;
CryptoPeople(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}