enum Gender{
MAN("男"),WOMAN("女");
String value;
private Gender(String value){
this.value = value;
}
}
class Person{
String name;
private Gender sex;
public Gender getSex() {
return sex;
}
public void setSex(Gender sex) {
this.sex = sex;
}
@Override
public String toString() {
return "姓名:"+ this.name+" 性别:"+ this.sex.value;
}
}
public class Demo129 {
public static void main(String[] args) {
Person p = new Person();
p.name = "狗娃";
p.setSex(Gender.WOMAN);
System.out.println(p);
}
}