Hi everyone,
I am preparing for
SCJP 1.4 exam which is due in October. I came across following confusing questions on arrays .
Q.1
int[] a={1,2,3,4};
int[] b={3,4,5,0};
System.out.println(a[(a=b)[0]]);
Above code compiles okay and prints 1. Explanation is given in mock exam is that araays are always evaluated from left to right i.e. a[b[3]]=> a[0]=>1
Q2.
int a[]=null; // was {1,2,3,4} (edited as next post)
System.out.println(a[m1()]);
Signature of method m1() is as follows
int m1() throws Exception
{ throw new Exception("Error in m1()");}
This compiles okay and throws Exception with message "Error in m1()". If principle of Q.1 is applied to this , this should have thrown NullPointerException. Why it is throwing Exception.
Can anyone put light on this.
Thanks in advance,
[ September 13, 2005: Message edited by: Barry Gaunt ]