源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Java通过接口实现匿名类的实例代码

  • 时间:2020-10-07 02:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Java通过接口实现匿名类的实例代码
[u]复制代码[/u] 代码如下:
package com.chase.test; /**  * 通过接口实现匿名类的实例  *  * @author Chase  *  * @date 2013-10-18 下午04:28:17  *  * @version V1.0  */ interface I1 {     void print();     void eat(); } public class AnonymousClass {     public static String excute(I1 c){         System.err.println("excute方法打印...");         c.print();         c.eat();         return "excute()返回的值...";     }     public String testExcute() {         return excute(new I1(){                 public void print() {                     System.out.println("调用匿名内打印...");                 }                 public void eat() {                     System.out.println("今天的饭菜好好吃...");                 }             }) ;         }     public static void main(String[] args) {         AnonymousClass entity = new AnonymousClass();         System.out.println(entity.testExcute());     } }
运行结果: [img]http://files.jb51.net/file_images/article/201310/20131018171222408.gif[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部