interface Inter
{
void method();
}
class Test
{
static class Demo implements Inter
{
public void method()
{
System.out.println("哈哈哈哈");
}
}
static Inter function()
{
return new Demo();
}
}
class Demodemo7
{
public static void main(String[] args)
{
Test.function().method();
}
}
//从主函数可以确定function()是一个static方法,因为是被类名调用。method()不可能是一个static方法
//所以Test.function()返回的是一个类
Test写成匿名内部类可写成
class Test
{
static Inter function()
{
return new Inter()
{
public void method()
{
System.out.println("哈哈哈哈");
}
};
}
}