Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

dan exam doubt 9  RSS feed

 
amit taneja
Ranch Hand
Posts: 814
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi.. in one question...

class MWC212 {
public static void main(String[] args) {
int[] a1[],a2[]; // 1
int []a3,[]a4; // 2
int []a5,a6[]; // 3
int[] a7,a8[]; // 4
}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. None of the above



the answer is "b"

with explanation...
An array variable is declared by placing brackets after the identifier or after the type name. A compile-time error occurs at the line marked 2, because the brackets appearing before the identifier for array variable a4 are not associated with the type or the identifier.


so is that means that

int []a5,a6[]; // 3
int[] a7,a8[]; // 4

.............
in above int []a5 is equalant to int[] a5

I mean is it does'nt matter that [] ( square brackets ) attached immediately before a5 in ( int []a5) valid as compare to explanation given by DAN ?

pls do give me suggesion..... got bit confused


regards,
amit
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int[] a1[],a2[]; // 1
is the same as
int a1[][];
int a2[][];

int []a5,a6[]; // 3
is the same as
int a5[];
int a6[][];

int[] a7,a8[]; // 4
is the same as
int a7[];
int a8[][];
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!