enum Color {
RED("红色"){
@Override
public String getContent(){
return this.toString();
}
},BULE("蓝色"){
@Override
public String getContent(){
return this.toString();
}
},GREEN("绿色"){
@Override
public String getContent(){
return this.toString();
}
} ;
private String title; // 枚举跟多实例一样,属性私有化
private Color(String title){ // 构造方法私有化
this.title = title;
}
@Override
public String toString(){
return this.title;
}
public abstract String getContent();
}
public class EnumDemo {
public static void main(String[] args) {
for (Color c :Color.values()
) {
System.out.println(c.ordinal() + "---" + c.name());
}
System.out.println( Color.RED.getContent());
}
}