首页 > 技术文章 > JDK8以后接口是可以定义实现方法,必须需要default修饰符修饰

mengbin0546 2019-12-08 10:13 原文

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();

    }
}

 

推荐阅读