本帖最后由 杨震 于 2012-8-30 11:25 编辑
- package com.itheima;
- /*
- * 定义一个交通枚举,包含红灯,绿灯,黄灯,需要有获得下一个灯的方法.例如:红灯获取下一个灯是绿灯,绿灯获取下一个灯是黄灯
- * @author 杨震
- *
- */
- public class Test3 {
- public static void main(String[] args) {
- Lamp red = Lamp.red;
- System.out.println(red.getNext());
- }
- }
- enum Lamp {
- red("green"), green("yellow"), yellow("red");
-
-
- private Lamp next;
-
- private Lamp(String next)
- {
- this.next = Lamp.valueOf(next);
- }
-
- public Lamp getNext()
- {
- return next;
- }
- }
- <img border="0" alt="" src="http://bbs.itheima.com/forum.php?mod=image&aid=6842&size=300x300&key=a110f35716b06bb978a1499fd7564458&nocache=yes&type=fixnone" aid="attachimg_6842">
复制代码 |
|