我们可以扩展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
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下