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
CAPITAL_LETTERS
to name your static final fields ( BUF
) 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.