如何在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP