面试真题——匿名内部类

来源:互联网 发布:淘宝自定义付款方式 编辑:程序博客网 时间:2024/06/03 23:40
interface Inter
{
public void method();
}

class Test
{
static Inter function()
{
return new Inter()
{
public void method()
{
System.out.println("method run");
}

};
}

}


public class InnerClassTest {

public static void main(String[] args) {
// TODO Auto-generated method stub
//test有个静态方法function,而且返回值为一个对象,
//只要对象 才能调用method方法
Test.function().method();
}


}


运行结果:


0 0
原创粉丝点击