class hello {
public static void main(String arg[]){
int[] c = { 2 };
final int[] d = { 3 };
}
static void useArgs(final int a, int b, final int[] c, int[] d) {
c[0]=d[0]; // no error
c = d; //error
}
}
guys can anybody can explain this behavior?
Variable c
is final. Which means that you cannot assign another value to that variable.
But the elements in the array itself are not final, which is why you are able to change the assignment on the elements like c[0]=d[0]
.