- java1.8 之后,允许在接口中写方法体,也就说方法的具体实现,就像是这样子
interface TestInterface{ default void print(int a, int b){ System.out.println(a + b); } static void print(int a, int b, int c){ System.out.printlb(a + " " + b + " " + c); } } class TestInterfaceImpl implements TestInterface{ } public class AAA{ public static void main(String []args){ //带有方法体的接口方法是不用重写的 TestInterface testInterface = new TestInterface(){}; testInterface.print(1,2); TestInterface.print(1,2,3); } }
8_27 接口中定义方法
最新推荐文章于 2021-02-27 09:31:59 发布