20150803-枚举

来源:互联网 发布:淘宝有哪些好的布料店 编辑:程序博客网 时间:2024/05/16 03:32

多用于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 :                ;            }    }}
0 0