枚舉裡定義屬性字段和構造方法
1enum Course{
2 COREJAVA("zhangsan"), //zhangsan學CoreJava
3 WEB("lisi"), //lisi學Web
4 EJB ("wangwu"); //wangwu學EJB
5
6 String name;
7 Course(String name){
8 this.name=name;
9 }
10 public String getName(){
11 return this.name;
12 }
13}
屬性字段,構造方法及抽象方法並存
enum Course{
COREJava("zhangsan"){
public void study(){
System.out.println("Study CoreJava");
}
},
WEB("lisi"){
public void study(){
System.out.println("Study Web");
}
},
EJB ("wangwu"){
public void study(){
System.out.println("Study EJB");
}
};
String teachName;
Course(String name){
this.teachName=name;
}
public String getName(){
return this.teachName;
}
public abstract void study();
}