Java-多例设计实现枚举-1

多例设计实现枚举-1

class jj{
	private final static jj c = new jj("春季");
	private final static jj x = new jj("夏季");
	private final static jj q = new jj("秋季");
	private final static jj d = new jj("冬季");
	private String dqjj;
	private jj(String dqjj){
		this.dqjj = dqjj;
	}
	public static jj getdqjj(int sign) {
		switch(sign) {
		case 1: return c;
		case 2: return x;
		case 3: return q;
		case 4: return d;
		default : return null;
		}
	}
	public String toString() {
		return dqjj;
	}
}

public class test{
	public static void main(String[] args) {
		System.out.println(jj.getdqjj(1));
	}
}
Console:
春季

你可能感兴趣的:(#枚举,Java)