*
The moose likes Beginning Java and the fly likes enum problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "enum problem" Watch "enum problem" New topic
Author

enum problem

Tarun Chauhan
Greenhorn

Joined: Jul 22, 2007
Posts: 4
Howdy ! I am not able to understand enum even though I have tried many sources. Could anyone suggest me some online resources where I could look it up.

My doubts and questions are :
(1). Is enum is a class or a method.
(2). If enum is a class then why don't we declare it with class keyword.

It would be very nice of anyone who could show me a complete program (and not a snippet) in which enum has been used.
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171
Originally posted by Hungry Joe:
Howdy ! I am not able to understand enum even though I have tried many sources. Could anyone suggest me some online resources where I could look it up.

My doubts and questions are :
(1). Is enum is a class or a method.
(2). If enum is a class then why don't we declare it with class keyword.

It would be very nice of anyone who could show me a complete program (and not a snippet) in which enum has been used.


(1). Is enum is a class or a method.

enum is a special kind of class, with an instance that represents each value of the enum


Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
Shoumin Li
Ranch Hand

Joined: Jul 06, 2007
Posts: 85
If enum is a class then why don't we declare it with class keyword.
I think is'a custom of c,
and many programer had used c/c++,(and many old language)
To attact the c/c++ programer ,Java kept some custom from C/C++


Java Blog
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8805
    
    5
Howdy there Hungry Joe,

First off, welcome to the ranch. We've found that things stay friendler when people use their real names as their display names, so I'd ask you to update your display name to follow that policy.

Second, since this question was posed in the beginner's forum, it's most useful to think of enums as being very similar to normal classes. They can have there own variables, constructors and methods.

hth,

Bert
[ July 25, 2007: Message edited by: Bert Bates ]

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Tarun Chauhan
Greenhorn

Joined: Jul 22, 2007
Posts: 4
Sorry about the name. I read the naming policy after Bert Bates adviced me to.
Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
Tarun -

The example on p. 673 of Head First Java by Kathy Sierra and Bert Bates seems to me to be a "complete program" using an enum - and if you write another class called something like TestEnum and move their main function to that class you should have a pretty good example of the enum's use.

I just finished an expression parser that uses an enum for the arithmetic operations - I could send it to you if you'd like, but since I'm just a beginner it's not so much a "perfect" example of Java programming!

Try experimenting with the Sierra and Bates example - it all becomes more obvious once you've tried out some things with it.
Tarun Chauhan
Greenhorn

Joined: Jul 22, 2007
Posts: 4
Hello Jinny,

Thanks for suggesting the example in Head First Java. Unfortunately, I have the old edition and 'enum' was not discussed in it. I just need to see a working program that uses 'enum'. It would be great if you send me your program. Thanks again.
Jinny Morris
Ranch Hand

Joined: Apr 29, 2007
Posts: 101
Tarun -

I sent the zipped source files to your gmail address - please let me know if any of it doesn't make sense!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enum problem
 
Similar Threads
Generics and enums
Oracle equivalent of MySQLs "enum"?
Enum doubt
enum doubt
ENUM'S