File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Query from Sun Sample questions. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Query from Sun Sample questions." Watch "Query from Sun Sample questions." New topic

Query from Sun Sample questions.

shyam ramineni
Ranch Hand

Joined: Jul 08, 2005
Posts: 43
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.

Shyam Ramineni

<a href="" target="_blank" rel="nofollow"></a>
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
C int [] x = (1,2,3);

Correct version:
C int [] x = {1,2,3};

SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
Mani vannan
Ranch Hand

Joined: Aug 21, 2004
Posts: 185
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

Joined: Sep 14, 1999
Posts: 2813
shyam, what message did you get when you attempted to compile and run code with option C in it?

SCWCD: Online Course, 50,000+ words and 200+ questions
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
I'll let the folks at Sun know that the ePractice is causing some JR discussions

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
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>;


<element_type> <array_name>[];

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
This is legal. It's called as array of arrays , a double dimentional array.

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Thanks Srini , it didn't click me that its a multidimensional array.
I agree. Here's the link:
subject: Query from Sun Sample questions.
It's not a secret anymore!