This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enum and inner class

 
susan waters
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic