黑马程序员技术交流社区

标题: 有点困惑 求解疑 [打印本页]

作者: zx7660    时间: 2016-3-10 12:48
标题: 有点困惑 求解疑
  1. class hello2{
  2.         public static void main(String[] args) {
  3.                 outer.method().show();
  4.         }
  5. }
  6. interface inter{
  7.         void show();
  8. }
  9. class outer{
  10.         public static [color=Red]inter[/color] method(){    //返回值为inter
  11.         return new inter(){
  12.         public void show(){
  13.         System.out.println("helloWord");
  14.         }
  15.         };
  16.                 }
  17. }
复制代码

这段代码注释里提到的返回值为什么要用inter呢?用void提示不兼容,使用inter返回值有什么意义?
作者: 孟茹    时间: 2016-3-10 16:21
因为你的retrurn值   是Inter型的:   return new inter(){;Static后面放的是返回值类型,你返回什么样的值,就加什么类型




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