//实现接口
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(); } }