• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Where do enums live?

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please correct me if my understanding is wrong. Enums are not objects. Enums are actually just ENUMS.

(There's a java.lang.Enum in the API. I am doubtful if they're the same though)

They can be declared inside and outside classes.

When enums are declared inside a class, and upon instantiation of that class, (1) they live on the heap. Hence (2) they're treated as class variables, or instance variables of that class.

Are (1) and (2) correct?

What happens when the enums are declared outside the class. Upon usage (or upon indirect invocation of constructors if they have) where do they live?

[ June 21, 2008: Message edited by: Denise Saulon ]
[ June 21, 2008: Message edited by: Denise Saulon ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An enum is a special kind of class. The constants of the enum are instances of that special classlike object; they are on the heap, just like other objects.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enums are a kind of special class:
-They can declare a constructor
-They can declare methods
-You can override methods

Example:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic