黑马程序员技术交流社区
标题:
有点困惑 求解疑
[打印本页]
作者:
zx7660
时间:
2016-3-10 12:48
标题:
有点困惑 求解疑
class hello2{
public static void main(String[] args) {
outer.method().show();
}
}
interface inter{
void show();
}
class outer{
public static [color=Red]inter[/color] method(){ //返回值为inter
return new inter(){
public void show(){
System.out.println("helloWord");
}
};
}
}
复制代码
这段代码注释里提到的返回值为什么要用inter呢?用void提示不兼容,使用inter返回值有什么意义?
作者:
孟茹
时间:
2016-3-10 16:21
因为你的retrurn值 是Inter型的: return new inter(){;Static后面放的是返回值类型,你返回什么样的值,就加什么类型
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2