标签:参数 integer sys enum 枚举 public his 访问控制 style
1 public class AboutEnum { 2 public static void main(String[] args) { 3 People p=People.MAN; 4 p.talk(); 5 } 6 } 7 enum People{ 8 // 疑问? 为什么构造函数只能出现在枚举对象后??? 9 // 当创建构造函数后,需要为创建枚举类时传入参数 10 MAN(People.MAN_NAME),WOMEN(People.WOMAN_NAME); 11 // 枚举类只能创建private及一下的访问控制权限的构造函数 12 private People(String name) { 13 if(name==MAN_NAME) { 14 this.age=20; 15 this.name=MAN_NAME; 16 }else { 17 this.age=22; 18 this.name=WOMAN_NAME; 19 } 20 } 21 22 private final static String MAN_NAME="zwk"; 23 private final static String WOMAN_NAME="mmr"; 24 private Integer age; 25 private String name; 26 27 public void talk() { 28 System.out.println("hello i‘m "+this.name+" i‘m "+this.age+" years old!"); 29 } 30 }
标签:参数 integer sys enum 枚举 public his 访问控制 style
原文地址:https://www.cnblogs.com/voryla/p/11633434.html