本帖最后由 追逐 于 2014-4-9 08:12 编辑
- public class EnumTest {
- public static void main(String[] args) {
- TrafficLamp tl = TrafficLamp.RED;
- System.out.println(tl);
- }
- //TrafficLamp是交通灯的意思
- public enum TrafficLamp {
- RED(30) {
- public TrafficLamp nextLamp() {
- return GREEN;
- }
- },
- GREEN(35) {
- public TrafficLamp nextLamp() {
- return YELLOW;
- }
- },
- YELLOW(3) {
- public TrafficLamp nextLamp() {
- return RED;
- }
- };
- public abstract TrafficLamp nextLamp();
- private int time;
- private TrafficLamp(int time) {
- this.time = time;
- }
- }
- }
复制代码
|