• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

First valid statement in a java class

 
Kareem Qureshi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I went through a test by Jaworski,
It says that
If a package statement is included in a source file then it must appear as first non blank line.
I think this is not correct
Please advice
Thanks in advance
Kareem
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such requirements stated in the JLS.
The only requirement is that the package statement (0 or 1 per compilation unit) must precede all import statements (zero or more) which in turn must precede the following class and/or interface declarations (zero or more).
It is perfectly allowed to have blank lines and/or comments before the package statement. There are numerous examples out there proving this point (just start with Sun's classes).
One more point, an empty file will compile and is a valid Java source file.
 
Kareem Qureshi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks i was sure of the answer but you know i am scheduled to take the exam two weeks from now and presently taking all the tests available on net. So that is why i am posting mistakes or things which i think are mistakes. so that i will not make that mistake ever again.
Kindly bear with me because my aim is to get 100%(pretty ambitious but achievable with your help)
of course the last exam i would take before the final exam is Valentin's mock test.
Thanks
Kareem
 
Radha Krishna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kareem
You can write package statement in the class after spaces or comments, but import statements and class declaration after package statement only
wish you all the best
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic