7.4.3 带抽像方法的枚举

    技术2024-04-21  10

    p { margin-bottom: 0.21cm; }

     

    public enum Trafficlamp {

    RED (30) {

    public Trafficlamp nextLamp() {

    return GREEN ;

    }

    },

    GREEN (30) {

    public Trafficlamp nextLamp() {

    return YELLOW ;

    }

    },

    YELLOW (20) {

    public Trafficlamp nextLamp() {

    return RED ;

    }

    };

     

    public abstract Trafficlamp nextLamp();

    int time ;

    private Trafficlamp( int time){ this . time = time;}

    }

    最新回复(0)