可不可以说,接口就是解决单继承问题的。实现本质也是继承,只不过要重写接口中的所有抽象方法?
public interface A { static void hello() { System.out.println("A.hello,静态方法"); } default void hi() { System.out.println("A.hi,普通方法"); } }
public class C implements A{ }
@Test public void IorE() { A c = new C(); c.hi(); A.hello(); }
运行结果:
A.hi,普通方法 A.hello,静态方法
pardon110
相关分类