A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© .ヤ牧马人〃 中级黑马   /  2014-11-19 11:58  /  1201 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

按照要求,补齐代码
        interface Inter { void show(); }
        class Outer { //补齐代码 }
        class OuterDemo {
            public static void main(String[] args) {
                      Outer.method().show();
                  }
        }
要求在控制台输出”HelloWorld”
求解,,

3 个回复

倒序浏览
Outer.method:类名调用方法,说明method必定是静态方法,而且返回值是一个对象。对象调用show输出helloworld.该对象是接口的子类,并覆写show方法,show中输出helloworld.
老毕的视频有讲
回复 使用道具 举报
通过匿名内部类的方式。
static Inter method()
{return new Inter(){
void show()
{System.out.println("hello  world");
}};
第二种方式:
static class  Inner implements Inter
{ void show()
{System.out.println("hello  world");
}
}
static Inter method()
{return new Inner();
}


}
回复 使用道具 举报
静态方法里定义匿名内部类,楼上已经写出来了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马