枚举

package 枚举;

public class Test {
public static void main(String[] args) {
//season. SPRING,这段执行就是获取一个season的对象
Season spring = Season.SPRING;
Season spring1 = Season.SPRING;
spring.showinfo();
//每次执行Season. SPRING获得是相同的对象,枚举类中的每个枚举都是单例模式的
System.out.println(spring.equals(spring1));
spring1.test();
}

}
enum Season implements ITest{
/**
* 春夏秋冬
*/
此处相当于在调用有参的私有构造
//private Season (String name, String desc)
SPRING(“春”,“春”),
SUMMER(“夏”,“夏”),
AUTUMN(“秋”,“秋”),
WINTER(“冬”,“冬”);
private final String name;
private final String desc;
private Season (String name , String desc){
this.name=name;
this.desc=desc;
}
public void showinfo(){
System.out.println(this.name+":"+this.desc);
}
@Override
public void test() {
System.out.println(“这是实现Itest接口方式”);
}
}
interface ITest{
void test ();
}

上一篇:Oracle之scott用户数据表


下一篇:order by a desc,b desc与order by a,b desc的区别