-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEnumDemo.java
More file actions
42 lines (34 loc) · 1.04 KB
/
EnumDemo.java
File metadata and controls
42 lines (34 loc) · 1.04 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
package chapter12;
//An enumeration of Apple varieties
enum Apple {
Jonathan, GoldenDel, RedDel, Winesap, Cortland
}
public class EnumDemo {
public static void main(String[] args) {
Apple ap;
ap = Apple.RedDel;
//Output an enum value
System.out.println("Value of ap " + ap);
System.out.println();
ap=Apple.GoldenDel;
//Compare two enum values
if(ap==Apple.GoldenDel){
System.out.println(" ap contains GoldenDel \n");
}
//use enum to control switch statement..
switch (ap){
case Jonathan:
System.out.println("Jonathan is Red");
break;
case GoldenDel:
System.out.println("Golden Delicious is Yellow");
break;
case RedDel:
System.out.println("Red Delicious is Red");
break;
case Winesap:
System.out.println("Case Winesap is Red");
break;
}
}
}