C language provides a type called enumeration. All possible values are listed in the definition of "enumeration" type, and the values of variables described as "enumeration" type cannot exceed the defined range.
For example, there are only seven days in a week, only twelve months in a year, and a class has six classes every week. It is obviously inappropriate to describe these quantities as integers, characters or other types.
Extended data
Definition of enumeration in c language
publicenumPersonnel {
Xiao Ming, Xiao Hong, Xiao Lan;
}
//Expand it.
publicenumPersonnel {
Xiao Ming ("male", 2 1, 86),
Xiaohong ("female", 22, 55),
Xiao Lan ("male", 23, 73);
privateStringsex
Private possession;
privateintresult
}
//Extend the isPass method to rewrite Xiaohong and then rewrite toString with the constructor getset.
publicenumPersonnel {
Xiao Ming ("male", 2 1, 86),
Xiaohong ("female", 22,55) {
@ Overlay
publicbooleanisPass(){
Returns false;;
}
},
Xiao Lan ("male", 23, 73);
privateStringsex
Private possession;
privateintresult
/* Structure */
privatePersonnel(Stringsex,intage,intresult){
this.sex = sex
This.age = age;
this.result = result
}
@ Overlay
publicStringtoString(){
Returnthis.name()+ "Gender:" +this.getSex()+ "Age:" +this.getAge()+ "Score:"+this.getresult ();
}
}
Baidu Encyclopedia-Enumeration