aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is this valid? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is this valid?" Watch "Is this valid?" New topic
Author

Is this valid?

K Ville
Ranch Hand

Joined: Aug 16, 2003
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.


Thinking is the talking of the soul with itself...-Plato
K Ville
Ranch Hand

Joined: Aug 16, 2003
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

Joined: Jun 17, 2003
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

Joined: Aug 16, 2003
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!
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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 ]

Groovy
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

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


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Munish Gulati
Ranch Hand

Joined: Aug 06, 2003
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 ]

Munish Gulati<br />SCJP 1.4<br />Albert Einstein: There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.
 
wood burning stoves
 
subject: Is this valid?