Java通过接口实现匿名类的实例代码
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());
}
}
运行结果: