This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Need help in this error ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need help in this error ??" Watch "Need help in this error ??" New topic
Author

Need help in this error ??

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Please consider the following code listing




Assume that everything else is correct . When i ran this code in the IDE i'm getting Illegal Start of expression at line number labelled PROBLEM. I faced this code in a mock question which had three answers a.) 12 b.)Compile time
3.) Runtime. so i guess it will be compile time error but I'm not able to understand the cause of the error. Please help
Hussein Mhanna
Greenhorn

Joined: Dec 02, 2010
Posts: 2
Hello gurpeet,

The array initializer (a ={1,2}) can only be used in the declaration of an array(Ex : int[] a = {1,2,3}).

So the answer is : The error is at Compile time.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

thanks for the reply Husain.........but is there some reason or is it in the syntax of array declarations for java...Can you please elaborate ??
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
It's a specification that array initializers should be present only in the array declaration.

From the JLS:
An array initializer may be specified in a declaration, creating an array and providing some initial values:


Source - JLS-Array Initializers - Navigate to Array Initializer if the URL is pointed to different section. It's pointing to a different section for me but I copied from Array Initializer.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

thanks John................the topic is resolved. Before closing i would like to ask you that I'm preparing for ocjp 6 exam and I'm currently following KB Scjp 6 Book. Should i also study JLS pdf.? or the book and mock exams are sufficient....
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
The book and mock exams should be sufficient. We have also have a page for mock exam links - ScjpMockTests.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help in this error ??
 
Similar Threads
Accessing a static variable from a generic class?
problem with enhanced for loop
goto in java:error
method
static variables declaration