package com.yz.demo01;
enum Grade{//------------------------》枚举定义的是多个常数
A,//90-100
B,//80-90
C,//70-80
D,//60-70
E//<60
}
class Person{
protected String name;
protected int age;
protected Grade grade;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
public Person(String name, int age, Grade grade) {
super();
this.name = name;
this.age = age;
this.grade = grade;
}
}
public class Demo02Enum {
public static void main(String[] args) {
Person p=new Person("悟空",10,Grade.D);
System.out.print(p.name+"\t"+p.age+"\t"+p.grade+"\t");
switch(p.grade){
case A://------------------------------------------------------------------------------------------>此处为什么不用Grade.A?可以查看switch中说的此处为常量?因为switch和case是一体 的,所以,参数既然调用了枚举类,case,就直接写了,语法规定,加上类名报错
System.out.print("成绩优秀");
break;
case B:
System.out.print("成绩良好");
break;
case C:
System.out.print("成绩中等");
break;
case D:
System.out.print("成绩及格");
break;
case E:
System.out.print("成绩不及格");
break;
}
}
}
enum Grade{//------------------------》枚举定义的是多个常数
A,//90-100
B,//80-90
C,//70-80
D,//60-70
E//<60
}
class Person{
protected String name;
protected int age;
protected Grade grade;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
public Person(String name, int age, Grade grade) {
super();
this.name = name;
this.age = age;
this.grade = grade;
}
}
public class Demo02Enum {
public static void main(String[] args) {
Person p=new Person("悟空",10,Grade.D);
System.out.print(p.name+"\t"+p.age+"\t"+p.grade+"\t");
switch(p.grade){
case A://------------------------------------------------------------------------------------------>此处为什么不用Grade.A?可以查看switch中说的此处为常量?因为switch和case是一体 的,所以,参数既然调用了枚举类,case,就直接写了,语法规定,加上类名报错
System.out.print("成绩优秀");
break;
case B:
System.out.print("成绩良好");
break;
case C:
System.out.print("成绩中等");
break;
case D:
System.out.print("成绩及格");
break;
case E:
System.out.print("成绩不及格");
break;
}
}
}