常用类 8 枚举 定义枚举要使用enum 关键字
用来限制一些关键信息
package oop2.Mathh;
public class Student {
private String name;
private Gender sex;
public Student(String name , Gender sex){
this.name = name;
this.sex = sex;
}
public Student (){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Gender getSex() {
return sex;
}
public void setSex(Gender sex) {
this.sex = sex;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", sex='" + sex + '\'' +
'}';
}
} package oop2.Mathh;
public enum Gender {
男,女
} package oop2.Mathh;
public class TestA {
public static void main(String[] args) {
Student student = new Student("zhangs",Gender.男); //在这里的sex就只能选择Gender里的枚举的内容
}
}