内部类的练习:
interface Inter
{
void method();
}
class Test
{
//补足代码,通过匿名内部类,
static Inter function()//可以由类名直接调用的,一定是静态的
{
//return new Inner_t();
return new Inter()
{
public void method()
{
System.out.println("method run");
}
};
}
}
public class InnerClassTest
{
public static void main(String[] args)
{
//Test.function():Test类中有一个静态的方法function
//.method():function这个方法运算后的结果是一个对象,而且是一个Inter型的对象
//因为只有是inter类型的对象,才可以调用method方法
Test.function().method();//method方法一定要被对象调用
//全写格式
//Inter in = Test.function();
//in.method();
show(new Inter()
{
public void method()
{
System.out.println("method show run");
}
});
}
public static void show(Inter in)
{
in.method();
}
}