匿名内部类的一个面试题

来源:互联网 发布:制作卡通人物的软件 编辑:程序博客网 时间:2024/05/21 09:18


/* 按照要求,补齐代码interface Inter { void show(); }class Outer { //补齐代码 public static ? method() }class OuterDemo {public static void main(String[] args) {  Outer.method().show();  }}要求在控制台输出”HelloWorld”*/class Test2 {public static void main(String[] args) {//Outer.method().show();//链式编程,每次调用方法后还能继续调用方法,证明调用方法返回的是对象Inter i = Outer.method();i.show();}}//按照要求,补齐代码interface Inter { void show(); }class Outer { public static Inter method() {return new Inter() {public void show() {System.out.println("show");}};}}


0 0
原创粉丝点击