枚 举

枚举类的定义
public enum Grade
{
A("100-90")
{
public String toString()
{
return "优";
}
},
B("89-80")
{
public String toString()
{
return "良";
}
},
C("79-70")
{
public String toString()
{
return "中";
}
},
D("69-60")
{
public String toString()
{
return "差";
}
},
E("59-0")
{
public String toString()
{
return "不及格";
}
};


private String value;

private Grade(String value)
{
this.value = value;
}

public String getValue()
{
return value;
}

}

枚举类的使用:
public void getScore(String name, Grade grade){
System.out.println(name + ":" + grade.name() + ":" +
grade.toString());
}


public static void main(String[] args)
{
Student s = new Student();
s.getScore("liujiao", Grade.A);
}

你可能感兴趣的:(Java)