- public class TrafficLamp {
- /**
- * @param args
- */
- public static void main(String[] args) {
- trafficLamp2 lamp = trafficLamp2.RED;
-
- }
-
- public enum trafficLamp2{
- RED(30){
- public trafficLamp2 nextLamp(){
- return GREEN;
- }
- },
- GREEN(45){
- public trafficLamp2 nextLamp(){
- return null;
- }
- },
- YELLOW(5){
- public trafficLamp2 nextLamp(){
- return null;
- }
- };//枚举值必须放在第一行
-
- public abstract trafficLamp2 nextLamp();
-
- private int time;
- private trafficLamp2(int time){
- int i=0;
- this.time = time;
- System.out.println(this.time+"---It is "+this.name()+" now-----"+(i++));
-
- }//构造方法私有化
- }
- }
复制代码 |