Java_39 枚举
//参考资料:
//https://blog.csdn.net/qq_27093465/article/details/52180865
//https://blog.csdn.net/newbie_907486852/article/details/81027512
//1. 枚举(enum)是一个特殊的class
//2. 这个class相当于final static修饰,不能被继承
package my;
enum Signal{
GREE,YELLO,RED
}
public class _54枚举 {
Signal color = Signal.RED;
public void change()
{
switch(color) //switch支持的类型byte,short,int,char,enum
{
case RED:
color = Signal.GREE;
System.out.println(color);
break;
case YELLO:
color = Signal.RED;
break;
case GREE:
color = Signal.YELLO;
break;
}
}
public static void main(String[] args)
{
_54枚举 bs = new _54枚举();
bs.change();
}
}
执行结果: