wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum and inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum and inner class" Watch "enum and inner class" New topic
Author

enum and inner class

susan waters
Ranch Hand

Joined: Feb 21, 2006
Posts: 68
Hello,
I am studying enum and getting lots of questions.

I can declare a class in an enum. but my question is "how can I instantiate that class" ?



How can I instantiate a class that is declared in an enum ?

Thanks for the reply
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Originally posted by susan waters:
How can I instantiate a class that is declared in an enum ?


You need to create an instance of myenum by myenum.TEST or by myenum.SAMPLE or by myenum.ENGLISH. All will return you an instance of myenum but remember different instances of myenum.



Since Testing class is an inner class, so you require an instance of outer class like above.

If Testing is a static nested class, then you don't need any myenum instance and you code will work.



Naseem
[ July 27, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
 
wood burning stoves
 
subject: enum and inner class