Java枚举类型实现构造方法、抽象方法

package org.local; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(weekday.A); System.out.println(TrafficLamp.YELLOW.nextLamp()); } public enum weekday{ A(1),B,C,D,E,F,G; private weekday(){}//实现私有构造方法 private weekday(int day){ System.out.println(day); } } public enum TrafficLamp{ RED {//内部匿名子类 @Override public TrafficLamp nextLamp() { // TODO Auto-generated method stub return GREEN; } }, GREEN { @Override public TrafficLamp nextLamp() { // TODO Auto-generated method stub return YELLOW; } }, YELLOW { @Override public TrafficLamp nextLamp() { // TODO Auto-generated method stub return RED; } }; public abstract TrafficLamp nextLamp(); } }  

你可能感兴趣的:(JAVA)