aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum - couple of questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum - couple of questions" Watch "enum - couple of questions" New topic
Author

enum - couple of questions

susan waters
Ranch Hand

Joined: Feb 21, 2006
Posts: 68
Hello Friends,

I have couple of questions on enum.

Q1: is it necessary that enum constants should be in the first place with comma separated once I declare like

enum TEST{
SHAPE, BALL, PEN; -> Correct one
}

enum TEST{
int j;
SHAPE, BALL, PEN; -> WRONG ONE. Since constants are not in first place.

so the bottom line for the first question is, If at all I have enum costants that should be in the first line is it right ?

Q2:

I have an emum like

enum MyEnum{
WATER,BOOK,CYCLE;
int i;
MyEnum(int i){
this.i=i;
}

-> I can not have these because there is one arg constructor declared so I need to have all the constants to be declared like WATER(2), BOOK(4),
CYCLE(9)
is it correct ?

q3: I can have enums declared in another enum and like a chain right ? this is something like inner classes. So in this case all the inner class rules apply to these enums also ?


q4: Is enum follow like class hierarchy ?

Hope my questions are not stupid. Thanks for the answers.


}
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Chapter 3: Enumerated Types (PDF Format) from Java 5.0 Tiger
susan waters
Ranch Hand

Joined: Feb 21, 2006
Posts: 68
This is usefull link and it answers my questions. Thanks very much.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Collection Links for SCJP 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enum - couple of questions