Q:

Assigning final array to an array in java

Consider the following code:-
int[] arr=new int[8];
final int[] finalArr=arr;

As arrays are reference types,does it mean arr is final now?If not then when i change it what happens to the finalArr?

A:

You have to strictly differentiate instances/objects from variables. final in Java is a concept that only applies to variables.
In your code you have two different variables that both refer to the same array instance. One of the variables is final, that neither affects the array nor the other variable at all.
final disallows re-assignment of the variable, it does not disallow altering the array. finalArr[1] = 4; is perfectly valid.
To illustrate this, consider
arr ---------|
             |----> instance created by new int[8]
finalArr ----|

You see two different arrays, both point to the same instance. final makes sure that you can not change the arrow going out of finalArr anymore. So it will always point to that array instance. But it does not give any restrictions regarding what you do to the array instance itself or to arr.

If you are coming from a C/C++ context, final is very different to const in that regard.

