Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum confusion

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
     
    Helen Ma
    Ranch Hand
    Posts: 451
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 583
    Firefox Browser Notepad Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 451
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 583
    Firefox Browser Notepad Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 808
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 583
    Firefox Browser Notepad Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic