黑马程序员技术交流社区
标题:
枚举
[打印本页]
作者:
张海刚
时间:
2011-8-3 12:55
标题:
枚举
file:///C:/Documents%20and%20Settings/Administrator/桌面/%5B4%7BB%5BQZ%7BZ%5BCRXM85M$@E~RD.jpg
file:///C:/Documents%20and%20Settings/Administrator/桌面/J%25V4L%25%5BG%25(FPP86THSRVFPR.jpg
System.out.println(redLamp);
System.out.println(greenLamp);
System.out.println(yellowLamp);
结果:
file:///C:/Documents%20and%20Settings/Administrator/桌面/$ZYUCII6TQF2K()Y$%7D%25%5DCVG.jpg
file:///C:/Documents%20and%20Settings/Administrator/桌面/$ZYUCII6TQF2K()Y$%7D%25%5DCVG.jpg
系统构造方法已经被覆盖,应该是常量得要用类去调用
作者:
匿名
时间:
2011-8-4 02:50
看不到图片
把我昨天的枚举Demo粘贴上来[code]public enum TrafficLamp
{
RED(45) {
@Override
public TrafficLamp nextLamp()
{
return GREEN;
}
} ,GREEN (50){
@Override
public TrafficLamp nextLamp()
{
return YELLO;
}
},YELLO(10) {
@Override
public TrafficLamp nextLamp()
{
return RED;
}
};
public abstract TrafficLamp nextLamp();
private int time;
private TrafficLamp(int time )
{
this.time=time;
}
}[/code]号称最难的枚举了 有抽象方法,有匿名内部类
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2