1、枚举类也是一个类,也可以有属性,等等:
public enum SeasonEnum{ SPRING, SUMMER, FALL, WINTER; }
这个是没有其他属性的。
package com.creditharmony.adapter.testCase.test; public class EnumTest { public void judge(SeasonEnum s) { switch (s) { case SPRING: System.out.println("春天"); break; case SUMMER: System.out.println("夏天"); break; case FALL: System.out.println("秋天"); break; case WINTER: System.out.println("冬天"); break; default: break; } } public static void main(String[] args) { for (SeasonEnum s : SeasonEnum.values()) { System.out.println(s); } new EnumTest().judge(SeasonEnum.FALL); } }
时间: 2024-10-08 11:13:01