- public class EnumDemo {
- public static void main(String[] args) {
-
- }
-
- public abstract static class Lamp {
- //常量,交通灯的固定三种颜色
- public static final int RED = 0;
- public static final int GREEN = 1;
- public static final int YELLO = 2;
-
- //该灯 持续点亮的时间
- private int mTime;
- //该灯的颜色,必须是 本类中定义的 三个颜色之一
- private int mColor;
-
-
- private Lamp(int pTime, int pColor){
- mTime = pTime;
- mColor = pColor;
- }
-
- public abstract Lamp next();
-
- public static Lamp Red = new Lamp(3, Lamp.RED) {
- @Override
- public Lamp next() {
- return Green;
- }
- };
-
- public static Lamp Green = new Lamp(3, Lamp.GREEN) {
- @Override
- public Lamp next() {
- return Yello;
- }
- };
-
- public static Lamp Yello = new Lamp(1, Lamp.YELLO) {
- @Override
- public Lamp next() {
- return Red;
- }
- };
-
- }
-
- }
复制代码 内部 类 Lamp 必须要声明为 static 为什么
|