posted 13 years ago
The interesting thing is that even though 'a' acts like it has been equated to 'b' during the inner evaluation, i.e. (a=b)[3], part of the expression (resulting in a value of 3), it retains it's old identity in the outer evaluation part of the expression (resulting in a value of 14), then going forward it reverts to being equal to 'b' again, as shown in the extra line added below.
----------------------------------------------
class Q55 {
public static void main(String[] args) {
int[] a={11,12,13,14};
int[] b={0,1,2,3};
System.out.println(a[(a=b)[3]]); // prints 14 (from old a array)
System.out.println(a[0]); // prints 0 (from new a array)
}
}
----------------------------------------------
SCJA 96%
SCJP 6 88%
skipping SCJD to work on passing SCWCD