-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumDemo.java
More file actions
56 lines (47 loc) · 1.18 KB
/
EnumDemo.java
File metadata and controls
56 lines (47 loc) · 1.18 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.sql.Struct;
import java.util.Scanner;
public class EnumDemo{
enum color{
green,yellow(45),red;
int depthLevel;
color(){
depthLevel = 100;
}
color(int value){
depthLevel = value;
}
int getdepthLevel(){
return depthLevel;
}
}
//background implementation of enum
/*
* class color{
* static final color green = new color();
* static final color yellow = new color();
* static final color red = new color();
* }
*/
public static void main(String[] args) {
color c = color.red;
switch(c){
case green:
System.out.println("it is green");
break;
case yellow:
System.out.println("it is yellow");
break;
case red:
System.out.println("it is red");
break;
default:
System.out.println("defualt case");
}
System.out.println("Yellow color depth level = "+color.yellow.getdepthLevel());
System.out.println("red order number in enum -> "+color.red.ordinal());
color[] C = color.values();
for(color co:C){
System.out.println(co);
}
}
}