接口interface

JDK8之前

public interface TestInterface {
    
    //jdk 8之前只有两种方法
    
    //成员变量
    String name="你猜";
    
    //成员方法(抽象方法)
    void test();
   
}

JDK8之后

默认方法 必须使用default修饰,默认会被public修饰


    /**
     *1.jdk8后 默认方法 必须使用default修饰,默认会被public修饰
     * 实例方法:对象的方法,必须使用实现类的对象看来访问
     */
    default void test1(){
    }

JDK9之后私有方法

使用private 修饰 私有方法只能在接口默认方法和其他的私有方法里边使用


    /**
     * 2.私有方法必须使用private修饰 (JDK9开始才支持)
     * 默认方法,其他的私有方法调用
     */
     private void test2(){

     }

静态方法 必须使用static修饰 ,默认会被public修饰


    /**
     *3.静态方法,必须使用static修饰,默认会被public 修饰
     */
    static void test3(){

    }

现在全部的方法

public interface TestInterface {
    
    //jdk 8之前只有两种方法
    
    //成员变量
    String name="你猜";
    
    //成员方法(抽象方法)
    void test();
    

    /**
     *1.jdk8后 默认方法 必须使用default修饰,默认会被public修饰
     * 实例方法:对象的方法,必须使用实现类的对象看来访问
     */
    default void test1(){
    test2();
    }

    /**
     * 2.私有方法必须使用private修饰 (JDK9开始才支持)
     * 默认方法,其他的私有方法调用
     */
     private void test2(){

     }

    /**
     *3.静态方法,必须使用static修饰,默认会被public 修饰
     */
    static void test3(){

    }


}

相关推荐

  1. Interface 接口

    2024-06-11 19:08:01       41 阅读
  2. 接口interface

    2024-06-11 19:08:01       17 阅读
  3. C# 接口 interface

    2024-06-11 19:08:01       25 阅读
  4. Go语言 Interface(接口)

    2024-06-11 19:08:01       20 阅读
  5. C#学习笔记_接口Interface

    2024-06-11 19:08:01       38 阅读
  6. 抽象(abstract)和接口interface

    2024-06-11 19:08:01       20 阅读
  7. Go 之 interface接口理解

    2024-06-11 19:08:01       19 阅读
  8. go语言接口之sort.Interface接口

    2024-06-11 19:08:01       18 阅读
  9. TypeScript中的接口interface )详解

    2024-06-11 19:08:01       40 阅读
  10. GO语言基础笔记(六):接口interface

    2024-06-11 19:08:01       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-11 19:08:01       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-11 19:08:01       5 阅读
  3. 在Django里面运行非项目文件

    2024-06-11 19:08:01       4 阅读
  4. Python语言-面向对象

    2024-06-11 19:08:01       6 阅读

热门阅读

  1. 使用redis构建简单的社交网站

    2024-06-11 19:08:01       14 阅读
  2. c语言之 **指针

    2024-06-11 19:08:01       16 阅读
  3. 008.googleNet-FashionMNIST-正确率90.510

    2024-06-11 19:08:01       20 阅读
  4. Android13 Settings 左上角箭头图标点击无效

    2024-06-11 19:08:01       15 阅读
  5. 【摘葡萄game】

    2024-06-11 19:08:01       15 阅读
  6. C++ Primer Chapter 8 The IO Library

    2024-06-11 19:08:01       8 阅读
  7. 深度学习的可微渲染

    2024-06-11 19:08:01       13 阅读
  8. Linux学习问题

    2024-06-11 19:08:01       18 阅读
  9. NAT

    NAT

    2024-06-11 19:08:01      20 阅读
  10. 享元模式

    2024-06-11 19:08:01       16 阅读