| Author |
Need help in this error ??
|
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 868
|
|
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
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
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: 868
|
|
|
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: 1778
|
|
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: 868
|
|
|
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: 1778
|
|
The book and mock exams should be sufficient. We have also have a page for mock exam links - ScjpMockTests.
|
 |
 |
|
|
subject: Need help in this error ??
|
|
|