匿名内部类的基本实现
抽象类或接口 通过匿名内部类 进行实现,
abstract class Person { public abstract void eat();}public class Demo { public static void main(String[] args) { Person p = new Person() { public void eat() { System.out.println("eat something"); } }; p.eat(); }}##################################
interface Person { public void eat();}public class Demo { public static void main(String[] args) { Person p = new Person() { public void eat() { System.out.println("eat something"); } }; p.eat(); }}############如果不是抽象类或接口,为pojo,那么也可以实现匿名内部类,重写父类方法,
匿名内部类就是重写父类或接口的方法,即将某方法进行特殊实现
浙公网安备 33010602011771号