JDK8

1. 接口default 与 static 关键字

/**
 * jdk8中接口可以使用声明default和static修饰的方法
 * static修饰的方法和普通的方法一样,可以被直接调用
 * default修饰的方法有方法体,就和普通的方法一样,可以被重写,有点像抽象类的方法一样,但是java是单继承多实现的
 */
public interface Today {

    void dream();

    void striver();

    default void victory(){
        System.out.println("未来");
    }

    static void test(){
        System.out.println("接口里的静态方法");
    }
    
    // jdk9 中还新增了private方法
    private void test3() {
        System.out.println("私有方法");
    };
}
View Code

相关文章:

  • 2021-07-06
  • 2022-12-23
  • 2021-07-14
猜你喜欢
  • 2021-10-18
  • 2021-09-10
  • 2021-08-07
  • 2021-12-19
  • 2021-11-28
  • 2021-10-12
相关资源
相似解决方案