1.枚举类对象实例化
2.枚举类的对象实例和构造方法逐个对应
3.枚举类中的构造函数多次复用
4.枚举类对象赋值输出对比
5.枚举类对象实例之间的比较
6.代码实例
package Test;
public enum Student {
student1("小刚"), student2("小红","15"), student3("小花","25","女");
private static final String ceshi = "测试住址";private static final String ce_sex = "男";private static final String name = "赋予名字";
private String userName;private String age;private String sex;private String address;
private Student() {
this(Student.name,Student.ce_sex,Student.ceshi);
}
private Student(String userName) {
this(userName,Student.ce_sex,Student.ceshi);
}
private Student(String userName, String age) {
this(userName,age,Student.ce_sex,Student.ceshi);
}
private Student(String userName, String age, String sex) {
this(userName,age,sex,Student.ceshi);
}
private Student(String userName, String age, String sex, String address) {
this.userName = userName;
this.age = age;
this.sex = sex;
this.address = address;
}
public String getUserName() {
return userName;
}
public String getAge() {
return age;
}
public String getSex() {
return sex;
}
public String getAddress() {
return address;
}
@Override
public String toString() {
return "Student{" + "userName='" + userName + '\'' + ", age='" + age + ',' + ", sex='" + sex + ',' + ", address='" + address + '\'' + '}';
}
public boolean isTrue(){
System.out.println("this=="+this);
System.out.println("student2=="+student2);
return this ==student2 ;
}
public static void main(String[] args) {
Student s1 = Student.student1;System.out.println(s1.toString());
Student s2 = Student.student2;System.out.println(s2.toString());
Student s3 = Student.student3;System.out.println(s3.toString());
//枚举类对象之间的比较
System.out.println( Student.student2.isTrue());
}
}