枚举
枚举:严格限制了输入的范围
Sex.java
package com.sxt.utils.enum1; public enum Sex { 男,女; }
Student.java
package com.sxt.utils.enum1; public class Student { private String name; private Sex sex;//sex 枚举类型 public Student(String name, Sex sex) {//sex 枚举类型 super(); this.name = name; this.sex = sex; } public Student() { super(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public Sex getSex() {//sex 枚举类型 return sex; } public void setSex(Sex sex) {//sex 枚举类型 this.sex = sex; } @Override public String toString() { return "Student [name=" + name + ", sex=" + sex + "]"; } }
TestSex.java
package com.sxt.utils.enum1; public class TestSex { public static void main(String[] args) { Student s = new Student(); s.setName("小明"); s.setSex(Sex.男); System.out.println(s.getName()); System.out.println(s.getSex()); } }
不找借口失败,只找理由成功!