Practice mode Java

Given final int a = {1, 2}; a = 9; System.out.println(a);, what is the result?

Correct answer B. It prints 9

Explanation

A final variable can be assigned only once, but for a reference that restricts the reference and not the object it points to. The array itself remains mutable, so a[0] = 9 is legal and 9 is printed. The statement a = new int[2] would be the compile-time error, since it reassigns the variable.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.