Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

enum - couple of questions

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


}
 
Ranch Hand
Posts: 2023
 
susan waters
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is usefull link and it answers my questions. Thanks very much.
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Collection Links for SCJP 1.5
 
Do you want ants? Because that's how you get ants. And a tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!