| |
1. 6. 2. 定义常量值,并使用它 |
|
- Using the final keyword to declare a variable.
- The final keyword specifies that the value of a variable is final and cannot be changed.
- It is a convention in Java to write constants in uppercase letters.
|
public class MainClass {
public static void main(String[] arg) {
final int FEET_PER_YARD = 3; // Constant values
final double MM_PER_INCH = 25.4; // that cannot be changed
System.out.println(FEET_PER_YARD);
System.out.println(MM_PER_INCH);
}
}
|
|
3
25.4 |
1. 6. 常数 | | 1. 6. 1. | 定义常量 | | | | 1. 6. 2. | 定义常量值,并使用它 | | |
|