首页 > 代码库 > 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 }
Enum
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。