创建使用匿名内部类格式:接口 对象=new 接口(){ 重写接口中的方法 };
创建接口test2
public interface test2{
public abstract void eat();
}
创建测试类test
使用匿名内部类,直接重写接口中的方法
public class test{
public static void main(String[] args) {
test2 t=new test2(){
@Override
public void eat(){
System.out.println("吃东西");
}
};
t.eat();
}
}