本帖最后由 熊永标 于 2013-3-28 17:27 编辑
- public class Weekday {
- private Weekday(){
-
- }
- public final static Weekday SUN=new Weekday(){//定义Weekday的子类
- @Override
- public Weekday nextDay(){//这相当于重写这个方法,
- System.out.println("aaa");
- return SUN;
- }
- };
- public final static Weekday MON=new Weekday(){
-
- };
-
- public Weekday nextDay(){
- if(this==SUN){
- return SUN;
- }else{
- return SUN;
- }
- }
- public String tostring(){
- return this==SUN?"SUN":"MON";
- }
- public static void main(String[] args) {
- System.out.println(Weekday.SUN.nextDay());
- }
- }
复制代码 结果为:
aaa
Weekday$1@c791b9
并没有什么错误呀? |