-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumTest.java
More file actions
27 lines (24 loc) · 943 Bytes
/
EnumTest.java
File metadata and controls
27 lines (24 loc) · 943 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
public class EnumTest {
public enum Members { JERRY, BOBBY, PHIL };
public Members selectedBandMember;
public static void main(String[] args) {
// Assigning an enum value to a variable
Members n = Members.BOBBY;
// We can compare enum instances using either
// == or the .equals() method. Usually == is
// considered better style.
if (n.equals(Members.JERRY)) System.out.println("Jerrrry!");
if (n == Members.BOBBY) System.out.println("Rat Dog");
// "Rat Dog" will be printed.
Members ifName = Members.PHIL;
switch (ifName) {
case JERRY: System.out.print("make it sing ");
case PHIL: System.out.print("go deep ");
case BOBBY: System.out.println("Cassidy! ");
}
// It'll print: "go deep Cassidy! " (everything after the case PHIL,
// i.e. case PHIL + case BOBBY). To print only the line that corresponds
// to the one particular name, the words "break;" must be put after each
// "case"-line.
}
}