File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum and inner class" Watch "enum and inner class" New topic

enum and inner class

susan waters
Ranch Hand

Joined: Feb 21, 2006
Posts: 68
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.

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

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
I agree. Here's the link:
subject: enum and inner class
It's not a secret anymore!