public final int MAX_ARRAY_SIZE = 25 ; |
例 final 关键字程序:Test.java |
public final class Test{ |
public static final int |
TOTAL_ |
NUMBER= 5 ; |
public int id; |
public Test(){ |
id = ++ |
TOTAL_ |
NUMBER; //非法,对final变量TOTAL_ |
NUMBER进行二次赋值了。 |
//因为++TOTAL_ |
NUMBER相当于 |
:TOTAL_NUMBER=TOTAL_NUMBER+ 1 |
} |
public static void main(String[] args) { |
final Test t = new Test(); |
final int i= 10 ; |
final int j; |
j = 20 ; |
j = 30 ; //非法,对final变量进行二次赋值 |
} |
} //源代码片段来自云代码http://yuncode.net |
|