Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class, when ??

 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
could any one tell me the use of inner classes ??
when is it used ??
thanks
raj
 
Frank Hale
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its probably a matter of preference when to use it. However its extremely useful when adding listeners to Swing components. Thats where I've seen it used extensively.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a class that is so tied to another class that it makes no sense for the one class to exist without the other.
An example from the API is the Entry class which is an inner class of the Map class. Entry represents a key-value pair in a Map so it makes sense to make Entry an inner class of Map.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic