This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Where do enums live? 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 "Where do enums live?" Watch "Where do enums live?" New topic
Author

Where do enums live?

Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
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 ]

SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Antonio Tercero
Ranch Hand

Joined: Jun 05, 2008
Posts: 110
Enums are a kind of special class:
-They can declare a constructor
-They can declare methods
-You can override methods

Example:


SCJP 5, SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where do enums live?
 
Similar Threads
Final's Puzzle
Rules Roundup Game: RuntimeExceptions and Math methods
Doubt in Rule Roundup Answer: catch block Exception Order
sample on illegal use of labeled continue and break
Comparing Table Changes in a Web Application