Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# Is this valid?

K Ville
Ranch Hand
Posts: 58
Given:
int[] a1[],a2[];

It seems to me that the 1st array obj ref is a 2d array, and the 2nd one is a simple array.

K Ville
Ranch Hand
Posts: 58
Got a follow-up from a mock I'm presently taking.
Given:
int[][] a = {{1,2,3},{4,5,6},{7,8,9,10}};
Is this also valid? Is it not that the 2nd pair of curly braces must be a set of parentheses?

Anupreet Arora
Ranch Hand
Posts: 81
Given:
int[] a1[],a2[];
It seems to me that the 1st array obj ref is a 2d array, and the 2nd one is a simple array.

Well both of them are 2D arrays. What you say would have been true if the declaration had been sth like:
int[] a1[],a2;
Given:
int[][] a = {{1,2,3},{4,5,6},{7,8,9,10}};
Is this also valid? Is it not that the 2nd pair of curly braces must be a set of parentheses?

Yes, this is valid as is this how multidimesional arrays are declared and contructed, using curly braces and not parenthesis.
Regards,
Anupreet

K Ville
Ranch Hand
Posts: 58
Thanks so much! But do you also mean that:

int[] a1[], a2
is a valid declaration? IF so, I never knew this. It would be a great help from you. God bless!

Ranch Hand
Posts: 8933
Yes it is! a1 is a 2 D array and a2 is a 1-D array!
Originally posted by K Ville:
Thanks so much! But do you also mean that:

int[] a1[], a2
is a valid declaration? IF so, I never knew this. It would be a great help from you. God bless!

[ September 02, 2003: Message edited by: Pradeep Bhat ]

Jessica Sant
Sheriff
Posts: 4313
check out this thread that just came up a couple weeks ago, it might help some more:
2 D Arrays

Munish Gulati
Ranch Hand
Posts: 37
And one more thing about the above discussion...now as you know
int[] a1[], a2; is a valid declaration so assignments
a1=a2;
or
a2=a1;
will result in a compiler error.
while in case int[] a1[],a2[] both a1 and a2 are 2D arrays so
a1=a2;
or
a2=a1;
are valid.
[ September 02, 2003: Message edited by: Thomas Paul ]
[ September 02, 2003: Message edited by: Karan Gulati ]