接口变量 [英] Interface Variables

查看:170
本文介绍了接口变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public interface A 
{

    public final int a = 0;

}

很多书都说接口中的所有变量(常量)当我明确地键入上面的语句但是没有包含关键字static时,它是隐式的公共静态final,它没有错误编译,并且可以通过静态方式引用,Aa表示它仍然是静态的。

Many books say that all variables (constants) in an interface are implicitly public static final yet when I type the above statement explicitly but do not include the keyword static it compiles with no errors and can be referenced by the static way, A.a which indicates that it is still static.

它是否是静态的,至于我必须是因为你不能实例化一个接口,好像你有这个实例变量那么你就永远不能访问数据成员a它是一个非静态字段。

Is it static or not, as to me it has to be since you cannot instantiate an interface, as if you had this "instance" variable then you could therefore never access the data member "a" as it is a non-static field.

推荐答案


很多书都说所有变量(常量)都在接口是隐式公共静态最终

Many books say that all variables (constants) in an interface are implicitly public static final

是的,你所观察到的与此完全一致。关键词是隐式一个静态变量,无论你是否写出 static 这个词。

Yes, and what you're observing is exactly consistent with that. The key word is implicitly: it is a static variable whether or not you write the word static.

这篇关于接口变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆