class Dog { protected void say() { } } public class Extend_Test { public static void main(String[] args) { Dog hashiqi = new Dog() { public void say() { System.out.println("2 ha"); } }; hashiqi.say(); } }
之前只见过接口的匿名内部类。