黑马程序员技术交流社区
标题:
求大神.....
[打印本页]
作者:
runner
时间:
2016-5-11 22:25
标题:
求大神.....
interface Inter { void show(); }
class Outer { //补齐代码 }
class OuterDemo {
public static void main(String[] args) {
Outer.method().show();
}
}
要求在控制台输出”HelloWorld”
作者:
我有上将潘凤
时间:
2016-5-11 23:13
public static Inter method() {
class Inner implements Inter {
public void show () {
System.out.println("HelloWorld");
}
}
Inter inter = new Inner();
return inter;
}
}
作者:
cxl1694095035
时间:
2016-5-12 10:04
public static void main(String[] args) {
Outer.method().show(); //链式编程,每次调用方法后,还能在继续调用,证明返回的是对象
}
}
interface Inter {
void show();
}
class Outer {
public static Inter method() {
return new Inter() {
public void show() {
System.out.println("helloworld");
}
};
}
}
作者:
dxw
时间:
2016-5-12 20:50
Outer.method().show();
能通过类名点调用的method()应该是个静态方法,
方法名method()能调用show()方法,说明他返回值是一个对象,匿名内部类就可以实现了
作者:
溪溪笑
时间:
2016-5-12 21:04
看一看。。。。。。。。。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2