java接口中变量的默认修饰符为 public static final

 

    int i = 3;

相当于

    public static final int i = 3;

 

 

java接口中方法的默认修饰符为 public abstract

 

    String fun(int a);

相当于

    public abstract String fun(int a);

 

 

接口中的方法是可以使用static修饰的,但必须在接口中实现该方法。

public interface Test {
    public static void test();   // 报错
}

 

public interface Test {
    public static void test(){};  // 正确
}

 

相关文章:

  • 2021-11-27
  • 2021-11-27
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-09-11
猜你喜欢
  • 2021-12-05
  • 2021-07-25
  • 2021-07-06
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案