直接贴出代码~~~
public abstract class Numbers {
private Numbers() {
};
public final static Numbers ZERO = new Numbers() { //创建Numbers类的子类对象
public Numbers nextNum() {
return ONE;
}
};
public final static Numbers ONE = new Numbers() {
public Numbers nextNum() {
return ZERO;
}
};
@Override
public String toString() {
return this == ZERO ? "ZERO" : "ONE";
}
}
public class ClassAsEnum {
/**
* @param args
*/
public static void main(String[] args) {
Numbers day = Numbers.ONE;
System.out.println(day);
System.out.println(day.nextNum());//子类对象调用其方法,这里为什么会报错??
}
}
请大神出来分析分析
|