• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query from Sun Sample questions.

 
shyam ramineni
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which three are legal array declarations? (Choose three.)

A int [42] x;
B int x [42];
C int [] x = (1,2,3);
D char [] myChars;
E int [] x = new int[] {2,4,5};
F int [] myScores [];

Answers given in the website are D,E,F.
Can anyone please tell me why C is not an answer.

Thanks
Shyam Ramineni
 
Georgy Bolyuba
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C int [] x = (1,2,3);

Correct version:
C int [] x = {1,2,3};
 
Mani vannan
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int a[] = {1,2,3} is the correct syntax. {} should be used to enclose the constant list during initilization and '()' is not.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shyam, what message did you get when you attempted to compile and run code with option C in it?
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll let the folks at Sun know that the ePractice is causing some JR discussions
 
Lalitha Vydyula
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any one explain why the below declaration is legal.
int [] myScores [];

As far as I know arrays can be declared in two ways.

<element_type>[] <array_name>;

or

<element_type> <array_name>[];



-Lalitha
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is legal. It's called as array of arrays , a double dimentional array.
 
Lalitha Vydyula
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Srini , it didn't click me that its a multidimensional array.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic