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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 他的好 中级黑马   /  2016-7-1 22:30  /  570 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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

2 个回复

倒序浏览
class Outer {         static int x=3;                  static class Inter         {                 void show()                 {                 System.out.println("HelloWorld");                 }         }         static void method()         {                 new Inter();         } }
回复 使用道具 举报
class Outer {
//补齐以下代码
        public static Inter method() {
                return new Inter() {                    // 重写该接口的子类对象
                        @Override
                        public void show() {
                                System.out.println("HelloWorld");
                        }
                };
        }
        
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马