A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 苏乞儿 中级黑马   /  2014-9-14 02:16  /  2254 人查看  /  20 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. /*
  2.         要求:补齐代码,输出helloworld
  3. */
  4. interface Inter
  5. {
  6.         void show();
  7. }
  8. class Outer
  9. {
  10.         //补齐代码,可以写两种形式,虽然基础班不做过多要求,但是感觉蛮有用的...
  11.         //做过的就算了,没做过的代码不用急着写,先看看自己有没有思路。。
  12. }
  13. class Test
  14. {
  15.         public static void main(String[] args){
  16.                 Outer.method().show();
  17.         }
  18. }
复制代码


20 个回复

倒序浏览
public static Outer method(){
                return new Outer();
        }
        public void show(){
                System.out.println("hello world");
        }



static class InterImpl implements Inter{

                public void show() {
                        System.out.println("hello world!");
                }
               
        }
        public static InterImpl method(){
                return new Outer.InterImpl();
        }
回复 使用道具 举报
再搞点难的
回复 使用道具 举报
本帖最后由 逍遥呆 于 2014-9-14 09:52 编辑
xpaibeyond 发表于 2014-9-14 03:32
public static Outer method(){
                return new Outer();
        }

这部分是什么意思?
static class InterImpl implements Inter

            
回复 使用道具 举报
逍遥呆 发表于 2014-9-14 09:48
这部分是什么意思?
static class InterImpl implements Inter

静态内部类 InterImpl 实现接口 Inter
回复 使用道具 举报
龙帅 发表于 2014-9-14 10:17
静态内部类 InterImpl 实现接口 Inter

明白了,谢谢
回复 使用道具 举报
逍遥呆 发表于 2014-9-14 09:48
这部分是什么意思?
static class InterImpl implements Inter

这个静态内部不实现上面那个接口也可以的,上面第2个method可以写成这样。
public static InterImpl method(){
                return new InterImpl();
        }

实现了Inter接口,method还可以写成这样,
public static Inter method(){
        return new InterImpl();
}
回复 使用道具 举报
xpaibeyond 发表于 2014-9-14 11:25
这个静态内部不实现上面那个接口也可以的,上面第2个method可以写成这样。
public static InterImpl meth ...

主要是想问,这题那个接口是不是一定要实现?
回复 使用道具 举报
逍遥呆 发表于 2014-9-14 13:46
主要是想问,这题那个接口是不是一定要实现?

  不是一定要实现。。
回复 使用道具 举报
xpaibeyond 发表于 2014-9-14 14:58
不是一定要实现。。

哦,谢谢
回复 使用道具 举报
匿名对象,二楼正解
回复 使用道具 举报
匿名对象 受教了
回复 使用道具 举报
谢谢分享
回复 使用道具 举报
学习,学习!
回复 使用道具 举报

互相学习,互相提高啊,哈哈
回复 使用道具 举报
不系之舟王 来自手机 中级黑马 2014-9-15 00:09:59
16#
不懂,真的得好好学习啊
回复 使用道具 举报
lq你微笑时好美 来自手机 中级黑马 2014-9-15 00:20:31
17#
明天开电脑运行::试试
回复 使用道具 举报

哈哈,我刚学,这都到极限了,,,,,不过可以再看看File中的那里有个关于FileFilter文件过滤器的匿名内部类。。。
回复 使用道具 举报
package Relect;

/*要求:补齐代码,输出helloworld
*/
interface Inter
{
      void show();
}
class Outer
{
     public static Inter method()
     {
             return new Inter(){public void show(){System.out.println("helloworld");}};
     }
        //补齐代码,可以写两种形式,虽然基础班不做过多要求,但是感觉蛮有用的...
      //做过的就算了,没做过的代码不用急着写,先看看自己有没有思路。。
}
public class Text
{
      public static void main(String[] args){
              Outer.method().show();
      }
}
回复 使用道具 举报
梦里听传说 发表于 2014-9-15 01:00
package Relect;

/*要求:补齐代码,输出helloworld

高手一直都在“民间”啊,啊哈
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马