File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes semicolon in Enums 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 "semicolon in Enums" Watch "semicolon in Enums" New topic
Author

semicolon in Enums

Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180
enum EnumCoffee {

BIG,HUGE,OVERWHELMING; //Line1
}; //Line2

I know that semicolon at LIne 2 is optional. Isthe semicolon at Line1 also optional.
Balagopal Kannampallil
Ranch Hand

Joined: Oct 18, 2004
Posts: 136

Yes, it is optional. It will work both ways.
But why do you want to introduce a semicolon there at Line1? Just playing around with code I hope.


SCJP 5.0 and now fighting with ExtJS
Balaji Bang
Ranch Hand

Joined: Apr 23, 2007
Posts: 180
I was going through a test And I got enum question. There was no semicolon at all in the programm. I was confused where it is optional....
Rafael Angarita
Ranch Hand

Joined: Jan 09, 2009
Posts: 67
The semicolon at Line 1 would be mandatory if there were more code following that line.



Rafael Angarita.
SCJP 6.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Banu Chowdary wrote:I know that semicolon at LIne 2 is optional. Isthe semicolon at Line1 also optional.

AFAIK it's not optional if you have fields, constructors, and / or methods in the enum after the enum constants. If you have any of these critters, then you will absolutely need the semicolon on Line1.

edit: as Rafael points out just before I did .
 
jQuery in Action, 2nd edition
 
subject: semicolon in Enums
 
Similar Threads
create jar problem: jarFile.jar: no such file or directory
class cast -- confused
Doubt in K&B SCJP 5: p62. semicolon after the declaration of enum
Discussing errata for K&B, SCJP 6
enums