匿名内部类
2015-08-02 21:04
246 查看
How
new 父类或接口(){继承父类或者实现接口所需的内容}; //注意理解这里的分号
new 父类或接口(){继承父类或者实现接口所需的内容}; //注意理解这里的分号
补全以下内容
interface Inter { void method(); } class Test { //补全代码,要求通过内部类 } class NiMingNeiBu { public static void main(String[] args) { Test.function().method(); } }
分析
interface Inter { void method(); } class Test { //静态 返回Inter static Inter function(){ //返回Inter,而Inter是一个接口,不能被实例-》new Inter(){实现接口}<=>实现了接口Inter的匿名类 return new Inter() { public void method(){ System.out.println("欧了"); } }; } } class NiMingNeiBu { public static void main(String[] args) { /*分析: 1:Test.function(),说明在Test内部定义了一个静态方法function() 2:.method()说明function返回的是一个实现了Inter的对象 */ Test.function().method(); } }
相关文章推荐
- protues与keil4联调
- Eclipse使用技巧
- java实现各种数字三角形
- UnrealEngine4初始化流程
- ubuntu 14.04 密码破解方法
- undefined reference问题总结
- STM32 microcontroller system memory boot mode
- Problem C HDU 5224
- Asp.net-知识总结(3)
- synchronized 与 static synchronized 的区别
- ContentResolver之读取联系人
- ContentReolver之打电话记录
- UnrealEngine4编码风格的思考
- iOS开发——UI进阶篇(十二)事件处理,触摸事件,UITouch,UIEvent,响应者链条,手势识别
- 面试准备--数据结构与算法(二)--二叉查找树的图文解析及其java实现
- 使用WebRTC搭建前端视频聊天室-01——入门篇
- 【Android多媒体】NuPlayer for HTTP Live Streaming【2】
- 8.2笔记
- 反射invoke方法之我见
- hdu1241(Oil Deposits)