wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum confusion" Watch "enum confusion" New topic
Author

enum confusion

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Two-Minute Drill

Enums (Objective 1.3)
  • An enum declared outside a class must NOT be marked static, final, abstract, protected, or private.


  • What does it mean ? ,it can be marked when enum is declared inside of class ?


    Tell the difficulties that i am difficult.
    Helen Ma
    Ranch Hand

    Joined: Nov 01, 2011
    Posts: 451
    Enum is a special type of class, according to either KB or Mughal / Rasumenssen / some Java tutorial online.
    So, if you have a class (not inner) , you cannot mark it static , protected or private.

    For final, I am not sure. Maybe we cannot extend a Enum and it is final implicitly. And for the same reason, it should not be abstract.
    saloni jhanwar
    Ranch Hand

    Joined: Feb 09, 2012
    Posts: 583

    Helen Ma wrote:Enum is a special type of class, according to either KB or Mughal / Rasumenssen / some Java tutorial online.
    So, if you have a class (not inner) , you cannot mark it static , protected or private.

    For final, I am not sure. Maybe we cannot extend a Enum and it is final implicitly. And for the same reason, it should not be abstract.


    Thanks Helen but my question was something different
    Helen Ma
    Ranch Hand

    Joined: Nov 01, 2011
    Posts: 451
    As I remember, the enum defined inside a class is implicitly static. By you can try to see if it compiles when this enum is declared protected, private, final.....

    As I remember, the enum insdie a class can be protected/private.
    saloni jhanwar
    Ranch Hand

    Joined: Feb 09, 2012
    Posts: 583

    Helen Ma wrote:As I remember, the enum defined inside a class is implicitly static. By you can try to see if it compiles when this enum is declared protected, private, final.....

    As I remember, the enum insdie a class can be protected/private.


    Thanks Helen

    After detailed study i got these all

    Outside of Class
  • It can have only default and public access modifiers.
  • It can have main method.


  • Inside of Class

  • Implicitly they are static so marked it or not doesn't matter .
  • All three access modifiers are allowed along with default access modifiers.
  • enums are already final, so to marked it final again cause compile error. and because of implicit declaration of final, abstract specifier will be useless.
  • enum constructor appears like it has default access modifier but it is implicitly private.



  • dennis deems
    Ranch Hand

    Joined: Mar 12, 2011
    Posts: 808
    saloni jhanwar wrote:Thanks Helen

    After detailed study i got these all

    Outside of Class
  • It can have only default and public access modifiers.
  • It can have main method.


  • Inside of Class

  • Implicitly they are static so marked it or not doesn't matter .
  • All three access modifiers are allowed along with default access modifiers.
  • enums are already final, so to marked it final again cause compile error. and because of implicit declaration of final, abstract specifier will be useless.
  • enum constructor appears like it has default access modifier but it is implicitly private.





  • Kudos to you! I predict you will score very well.
    saloni jhanwar
    Ranch Hand

    Joined: Feb 09, 2012
    Posts: 583

    Dennis Deems wrote:
    saloni jhanwar wrote:Thanks Helen

    After detailed study i got these all

    Outside of Class
  • It can have only default and public access modifiers.
  • It can have main method.


  • Inside of Class

  • Implicitly they are static so marked it or not doesn't matter .
  • All three access modifiers are allowed along with default access modifiers.
  • enums are already final, so to marked it final again cause compile error. and because of implicit declaration of final, abstract specifier will be useless.
  • enum constructor appears like it has default access modifier but it is implicitly private.





  • Kudos to you! I predict you will score very well.

    thanks
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: enum confusion
     
    Similar Threads
    Enum
    Enum doubt
    Doubt regarding enum
    declaring Enum variable as "final"
    Declaring Enums in a class