• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enum Constructors

 
Ranch Hand
Posts: 62
Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a query regarding enums. I don't if it's too obvious to ask such a doubt; but pardon me, am new to Java5.0 and have just started preparing for SCJP5.0.

Iam trying to code using enums and found out that enum constructors can either have default access or private access. Why are the other access modifiers not allowed for enums? I read somewhere that it's to prevent enum instance being created by ourselves; but in that case why is default allowed? Default access or package access will also allow the same in the package in which the enum is defined right?

Kindly some1 help me:(
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the only modifier allowed for an enum constructor is private, and if you don't write it explicitly the compiler will just add it to you. you may think that its given the default modifier however its not. remember the constructor of an enum can be accessed only withing the enum, no one can call it from outside. bottom line enums are used to represent Constants.
 
Jisha Anand
Ranch Hand
Posts: 62
Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Omar!
 
reply
    Bookmark Topic Watch Topic
  • New Topic