开发者

What is the equivalent keyword for extern in java?

I have one public static variable in one file and how can I export the same variable to ot开发者_如何转开发her files?

For ex:-

file1.java

public final static int buf = 256;

file2.java

How can I access the variable "buf" in this file?


File1.buf. More generally: ClassName.FIELD_NAME. A few notes

  • use CAPITAL_LETTERS to name your static final fields (BUF)
  • use static final rather than final static (not crucial, but it is a widely accepted style)


File1.buf

correct definition: public static final int BUF = 256;

so you would call it in other class:

File1.BUF;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜