/**
* 匿名内部类的方法调用
* @author Administrator
*
*/
interface Inter{
public abstract void show();
public abstract void show2();
}
class OuterA{
public void method(){
/*
new Inter(){
public void show(){
System.out.println("show");
}
public void show2(){
System.out.println("show2");
}
}.show();
new Inter(){
public void show(){
System.out.println("show");
}
public void show2(){
System.out.println("show2");
}
}.show2();
*/
//优化版
Inter i = new Inter(){//多态
public void show(){
System.out.println("show");
}
public void show2(){
System.out.println("show2");
}
};
i.show();
i.show2();
}
}
public class InterClass {
public static void main(String[] args){
OuterA o = new OuterA();
o.method();
}
}
匿名内部类的方法调用
最新推荐文章于 2023-10-15 15:57:27 发布