多用于switch语句
范例:
//枚举类:
public enum Sex {
FAMALE,MALE;
}
//用枚举的类:
public class Student {
private Sex sex;
private String name;
public Student(String name){
this.name = name;
}
public Sex getSex() {
return sex;
}
public void setSex(Sex sex) {
this.sex = sex;
}
}
//测试:
public class Test_enum {
public static void main(String[] args) {
Student stu = new Student("zhangsan");
stu.setSex(Sex.FAMALE);
switch(stu.getSex()){
case FAMALE:
;
case MALE:
;//如果是男,则执行的代码
default :
;
}
}
}