第十三课(枚举)

class FreshJuice {// 枚举:当做数据类型,只能接固定值(定义值) enum FreshJuiceSize{ SMALL, MEDIUM, LARGE }FreshJuiceSize size; // size 是类FreshJuice的实体变量 }public class FreshJuiceTest {public static void main(String args[]){FreshJuice juice = new FreshJuice(); // 类.枚举名.枚举值 juice.size = FreshJuice.FreshJuiceSize.MEDIUM; System.out.println("Size: " + juice.size); if (juice.size == FreshJuice.FreshJuiceSize.MEDIUM) { System.out.println("显示中杯页面"); }else if (juice.size == FreshJuice.FreshJuiceSize.SMALL) { System.out.println("显示小杯页面"); }else if (juice.size == FreshJuice.FreshJuiceSize.LARGE) { System.out.println("显示大杯页面"); }} }

    推荐阅读