简体   繁体   中英

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 other 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM