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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

package com.xiaolong.nonameclass;
//补全代码,输出helloworld
public class Demo1 {

        public static void main(String[] args) {
                // TODO Auto-generated method stub
                        Outer.method().show();                        //实际上是Inner对象调用show方法
        }

}
class Outer{
        public static Inner method(){                                                        //返回值为Inner类型
                        return new Inner(){
                        public void show(){
                                System.out.println("hello world");                        //匿名内部类
                        }
                };
               
               
        }
}
interface Inner{
        void show();
}

1 个回复

倒序浏览
求大神解释匿名内部类什么意思?好乱
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马