我们可以扩展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 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练