接口注意事项---再次巩固,多看看不会亏!

在接口中,属性都是默认public static final修饰的

如果属性是基本数据类型,需要赋初始值,若是引用类型,也需要初始化,因为默认有final修饰,必须赋初始值

private final static int answer = 42;
public static int answer = 42;
final static answer = 42;没数据类型
int answer;没初始化!!!

 

interface OOP {
}
public interface OOP {
}
abstract interface OOP {
}

 这三个定义接口形式都没毛病!!!其余的修饰符修饰都是错的!!!

interface OOP {
    int i=1;
    Integer g=null;
    public int j=2;
    static int p=3;
    final  int k=4;
    public static Integer x=null;
}

接口中这样定义属性都没错!!!

再强调一遍啊!!!必须赋值!不管你是基本类型或是引用类型

 

interface OOP {
    void f1();
    int f2();
    abstract void f3();
    public void f4();
    public abstract void f5();
}

 接口中这样定义方法都没错!!!

注意啊!JDK1.8  还不能用 default  static  定义方法!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C_x_330

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值