interface IColor{
public String getContent();
}
enum Color implements IColor{
RED("红色"),BULE("蓝色"),GREEN("绿色") ;
private String title; // 枚举跟多实例一样,属性私有化
private Color(String title){ // 构造方法私有化
this.title = title;
}
@Override
public String toString(){
return this.title;
}
@Override
public String getContent() {
return this.title;
}
}
public class EnumDemo {
public static void main(String[] args) {
for (Color c :Color.values()
) {
System.out.println(c.ordinal() + "---" + c.name());
}
IColor c = Color.RED;
System.out.println(c.getContent());
}
}
枚举类实现接口
最新推荐文章于 2023-02-18 23:11:49 发布