JDK8以后接口是可以定义实现方法,必须需要default修饰符修饰
package com.company.java.oop.cls; interface IB { default void doMethod1() { System.out.println("IB"); } default void doMethod2() { System.out.println("domethod2"); } } class B implements IB {} public class TestInterface { public static void main(String[] args) { IB a2 = new B(); } }