File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in this error ??

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic