在课堂上重新初始化变量?

时间:2015-09-16 01:57:40

标签: java

当我在界面中声明变量使其变为public class AnalysisAssignmentMod { // fill the contents of the array passed as parameter at random public static void fillArray(int array[]) { Random rnd = new Random(); for(int i =0; i < array.length; i++) { array[i] = rnd.nextInt(Integer.MAX_VALUE); } } // returns a new array with a copy of each of the values from the array passed as parameter public static int[] copyArray(int[] array) { int array1[] = new int[array.length]; for(int i = 0 ; i < array.length; i++) { array1[i] = array[i]; } return array1; } public static void main(String[] args){ int[] mainArray = new int[10]; int[] nextArray = new int[10]; fillArray(mainArray); nextArray = copyArray(mainArray); System.out.println(Arrays.toString(mainArray)); System.out.println(Arrays.toString(nextArray)); } } 时,我如何能够在班级中更改public static final的值?

a

1 个答案:

答案 0 :(得分:0)

你是shadowing变量。根据链接的维基百科条目,

  

computer programming中,当在某个scope(决策块,方法或内部类)中声明的变量与声明的变量具有相同的名称时,会发生变量阴影在外部范围内。

在您的示例中,您正在创建名为a的新变量。它与界面中声明的a无关。

System.out.println(((xyz) new Test2()).a);

仍会输出1

相关问题