/*
1、在main方法里面有一个Outer类名调用了method()方法
那么这个method()方法肯定是Outer类中的一个静态的方法
(因为只有本类中的静态方法才能直接被类名调用)
2、在method()方法后面又直接调用了show()方法。show()方法又是Inter
接口中的方法,但是Inter接口不能直接创建对象,也没有被实现。
所以就要想到使用匿名内部类去实现Inter接口
3、因为匿名内部类是没有名字的,所以它返回的是Inter接口类型
匿名内部类的格式:new 外部类名或者接口名(){覆盖类或者接口中的代码。(也可以自定义内容)};
*/
interface Inter{
public abstract void show();
}
class Outer{
//请完成Outer的内容
public static Inter method(){
return new Inter(){
public void show(){}
};
}
}
class InterClassTest{
public static void main(String[] args){
Outer.method().show();
}
} |