Java匿名内部类继承类和实现接口

//实现接口
public
interface MyInterface { void pri(); } public class TestClass1 { public MyInterface test(){ return new MyInterface(){ public void pri() { System.out.println(1); } }; } public static void main(String[] args) { MyInterface my = new TestClass1().test(); my.pri(); } }
//继承类
public abstract class AbstructClass {
    abstract void pri();
}

public class TestClass2 {
    public AbstructClass te(){
        return new AbstructClass(){
            void pri() {
                System.out.println(1);
            }
        };
        
    }
    public static void main(String[] args) {
        AbstructClass abc = new TestClass2().te();
        abc.pri();
    }
}
原文地址:https://www.cnblogs.com/blog-wp/p/3359380.html