黑马程序员技术交流社区

标题: 匿名内部类 [打印本页]

作者: lrx    时间: 2016-4-24 12:14
标题: 匿名内部类
                按照要求,补齐代码
                interface Inter { void show(); }
                class Outer { //补齐代码 }
                class OuterDemo {
                        public static void main(String[] args) {
                                  Outer.method().show();
                          }
                }
                要求在控制台输出”HelloWorld”
作者: ruijin    时间: 2016-4-24 17:09
        public static Inter method(){
                return new Inter() {
                       
                        @Override
                        public void show() {
                                System.out.println("Hello World!");
                               
                        }
                };
        }
作者: Petergee    时间: 2016-4-24 17:23
    面试题来着  
public static Inter method(){
                return new Inter() {
                        public void show() {
                                System.out.println("Hello World");
                                
                        }
                };
        }




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2