枚舉
1.定義的每個枚舉類型都繼承自java.lang.Enum類柳恐,枚舉中的每個成員默認(rèn)都是public static final的。
2.每個成員都是枚舉類型的一個實例豌鸡。
//常用枚舉
enum Color{
red,
white,
yellow
}
//變體枚舉
public static void main(String[] args) {
for (Color c :Color.values()){
System.out.println(c.getRGB());
}
}
enum Color{
red(2),yellow(23),blue(30);
int RGB;
private Color(int rGB) {
RGB = rGB;
}
public int getRGB() {
return RGB;
}
public void setRGB(int rGB) {
RGB = rGB;
}
}