我们可以扩展Java枚举吗?
不,我们不能扩展Java中的枚举。Java枚举可以隐式扩展java.lang.Enum类,因此枚举类型不能扩展另一个类。
语法
public abstract class Enum> implements Comparable, Serializable {
//一些陈述
}枚举
一个枚举 类型是在添加了特殊的数据类型的Java1.5版本。
一个枚举 用来定义一个常量集合,当我们需要预定义的值列表,它并不代表某种数字或文本数据,我们可以使用一个枚举。
枚举 是常量 ,默认情况下,它们是static和final。因此,枚举类型字段的名称以大写 字母表示。
公共 或受保护的 修饰符只能与顶级枚举声明一起使用,但是所有访问修饰符都可以与嵌套枚举声明一起使用。
示例
enum Country {
US {
public String getCurrency() {
return "DOLLAR";
}
}, RUSSIA {
public String getCurrency() {
return "RUBLE";
}
}, INDIA {
public String getCurrency() {
return "RUPEE";
}
};
public abstract String getCurrency();
}
public class ListCurrencyTest {
public static void main(String[] args) {
for (Country country : Country.values()) {
System.out.println(country.getCurrency() + " is the currecny of " + country.name());
}
}
}输出结果
DOLLAR is the currecny of US RUBLE is the currecny of RUSSIA RUPEE is the currecny of INDIA
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短