Sample Sun Certification Question

 
public static void main (String args[]) {
int[]a1[]=new int[3][3]; //3
int a2[4]={3,4,5,6}; //4
int a2[5]; //5

}}

What is the result of attempting to compile and run the program ?.

  1. Compile time error at lines 3,4,5

  2. Compile time error at line 4,5
  3. Compile time error at line 3

  4. Run time Exception

  5. None of the above

Ans: 2

Explanation:

No value should be specified in the right side of brackets when constructing an array

Blog Widget by LinkWithin

Originally posted 2009-07-31 10:22:35.

Share