如何用Java编写常量名称?
在编写常量名称时,建议
用大写字母写所有字母。
如果常量包含多个单词,则应使用下划线(_)分隔。
示例
public class ConstantsTest {
public static final int MIN_VALUE = 22;
public static final int MAX_VALUE = 222;
public static void main(String args[]) {
System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE);
System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE);
}
}输出结果
Value of the constant MIN_VALUE: 22 Value of the constant MAX_VALUE: 222