首页 > 代码库 > Enum

Enum

1.定义时使用enum关键字定义。

2.隐式继承了java.lang.Enum类,所以不能再继承其他类了。

3.隐式的final修饰符,所以不能被其他类继承。

技术分享
 1 package enumTest;
 2 
 3 public enum Week {
 4     MONDAY,
 5     TUESDAY,
 6     WEDNESDAY,
 7     THURSDAY,
 8     FRIDAY,
 9     SATURDAY,
10     SUNDAY;
11     
12     public static void main(String[] args)
13     {
14         Week day = Week.FRIDAY;
15         
16         switch(day)
17         {
18             case MONDAY:
19                 System.out.println("it is Monday! work hard!");
20                 break;
21             case TUESDAY:
22                 System.out.println("it is Tuesday! work hard hard!");
23                 break;
24             case WEDNESDAY:
25                 System.out.println("it is Wednesday! tired!");
26                 break;
27             case THURSDAY:
28                 System.out.println("it is Thursday! waiting weekend!");
29                 break;
30             case FRIDAY:
31                 System.out.println("it is Friday! will have a nice night!");
32                 break;
33             case SATURDAY:
34                 System.out.println("it is Saturday! lovely day!");
35                 break;
36             case SUNDAY:
37                 System.out.println("it is monday!oh no tomorrow is Monday again!");
38                 break;
39             default:
40                 System.out.println("it is monday! what!");
41                 
42         }
43     }
44 }
View Code

 

Enum