枚举类的创建与使用

public enum TestEnum {

    /**
     * 年级-班级
     */
    CLASS_ONE_SENIOR_HIGH_SCHOOL("高中","1班"),  //多个使用逗号隔开,以分号结束
    CLASS_TWO_SENIOR_HIGH_SCHOOL("高中","2班");


    private String key;
    private String value;

    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    TestEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public static void main(String[] args) {
        System.out.println(TestEnum.CLASS_ONE_SENIOR_HIGH_SCHOOL.getKey()
                +TestEnum.CLASS_ONE_SENIOR_HIGH_SCHOOL.getValue());//高中1班
                
        System.out.println(TestEnum.CLASS_TWO_SENIOR_HIGH_SCHOOL.getKey()
                +TestEnum.CLASS_TWO_SENIOR_HIGH_SCHOOL.getValue());//高中2班
    }
}

你可能感兴趣的:(Java)