- public class Demo {
- public static void main(String[] args) {
- System.out.println(Light.RED.nextLight());
- }
- }
复制代码
- public enum Light {
- RED(30) {
- @Override
- public Light nextLight() {
- return GREEN;
- }
- },GREEN(45) {
- @Override
- public Light nextLight() {
- return YELLOW;
- }
- },YELLOW(5) {
- @Override
- public Light nextLight() {
- return RED;
- }
- };
- private int time;
- private Light(int time){
- this.time=time;
- }
- public abstract Light nextLight();
-
-
- }
复制代码
枚举中的方法为什么是抽象的? |
|