1.无法new出新的实例
2.构造方法必须是私有的并且只能是私有的
3.只能定义访问器,不能定义构造器。
4.限定对象个数并且提前定义好,除了这个特点之外其他用法跟普通类没区别
5.定义枚举类test
public enum test{
AA(12,"小红1",150),BB(13,"小红2",160),CC(13,"小红3",161),DD(14,"小红4",167);
//定义了四个对象
private int age;
private String name;
private int height;
private test(int a,String n,int h){//构造方法必须是私有的
age=a;
name=n;
height=h;
}
public int getHeight()//访问器
{
return height;
}
public String toString(){
return "age:"+age+",name:"+name+",height:"+height;
}
}
6.使用枚举类
public class tst{
public static void main(String []args){
test x=test.AA;//x=AA(12,"小红1",150)
test y=test.BB;//y=BB(13,"小红2",160)
System.out.println(x);//x.toString()
System.out.println(y);//y.toString()
System.out.println(test.CC.getHeight());
}
}