A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Enums
Sandeep Vaid
Ranch Hand
Joined: Feb 27, 2006
Posts: 390
posted
Sep 06, 2006 06:53:00
0
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
posted
Sep 06, 2006 06:59:00
0
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
posted
Sep 06, 2006 08:04:00
0
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.
enum E{E1,E2} class Temp { }
2. Enum can be declared in a class (its own class), however it's variable is declaerd in another class.
class A { enum E{E1,E2} } class B { A.E e1; }
3. Enum along with it's variable (instance variable) can be part of a single class..
Class A { enum E{E1,E2}; E e1; }
Let me know if i am correct.
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
posted
Sep 06, 2006 08:46:00
0
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
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter