java_实现接口的枚举类

时间:2023-02-07 15:26:28
package ming;

interface GenderDoc {
void info();
} enum Gender implements GenderDoc {
// public static final Gender MALE = new Gender("男");
MALE("男") {
public void info() {
System.out.println("gender male information");
}
},
FEMALE("女") { public void info() {
System.out.println("gender female information");
} }; private String name; public String getName() {
return name;
} private Gender(String name) {
this.name = name;
} } public class enumTest {
public static void main(String[] args) {
// 通过valueof方法获取指定枚举类的值
Gender gf = Enum.valueOf(Gender.class, "FEMALE");
Gender gm = Enum.valueOf(Gender.class, "MALE"); System.out.println(gf + " is stand for " + gf.getName());
System.out.println(gm + " is stand for " + gm.getName()); gf.info();
gm.info(); } }