aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enums Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Enums" Watch "Enums" New topic
Author

Enums

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
In Kathy & Bert's book, page no 60 it's written that

Enums can be declared as their own seperate class, or as a class member

But the following 2 examples shows that enums can be declared outside the class or inside the class.
Kaarthick Ramamoorthy
Greenhorn

Joined: Sep 01, 2006
Posts: 23
Hi,
"Enums can be declared as a separate class " means Enums can be declared like class declaration.

class A
{
}

similiarly

enum e
{
}
Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
No i don't think so it means that. This is the basic enum declaration syntax no matter where you declare it.

I understand :

1. Enum can be declared outside all classes.


2. Enum can be declared in a class (its own class), however it's variable is declaerd in another class.

3. Enum along with it's variable (instance variable) can be part of a single class..




Let me know if i am correct.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I believe that the first and third of your three cases are those meant by K & B.

The second case is not wrong but it will not be seen very often.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enums
 
Similar Threads
Declaring Enums in a class
Where do enums live?
modifier for enum
Deleting session deletes all my sessions
enums