标签:enum
public class EnumTest02{ //入口 public static void main(String[] args){ int a = 10; int b = 0; Result retValue = divide(a,b); if(retValue==Result.SUCCESS){ System.out.println("成功"); }else if(retValue==Result.FAIL){ System.out.println("失败"); } } //实现需求 public static Result divide(int a,int b){ try{ int c = a / b; return Result.SUCCESS; //成功 }catch(Exception e){ return Result.FAIL; //失败 } } } //定义一个枚举类型 enum Result{ //成功和失败 //规范要求:大写 SUCCESS,FAIL //有限的. } //四季 enum Season{ SPRING,SUMMER,AUTUMN,WINTER } //颜色 enum Color{ GREEN,BLUE,RED }
本文出自 “gaogaozi” 博客,请务必保留此出处http://hangtiangazi.blog.51cto.com/8584103/1662533
标签:enum
原文地址:http://hangtiangazi.blog.51cto.com/8584103/1662533