It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Advantages of inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Advantages of inner classes" Watch "Advantages of inner classes" New topic
Author

Advantages of inner classes

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

What are the advantages of inner class?


Groovy
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
There are many advantages, though some of them are really personal or design preference.
1 - with inner classes you can access private members of the enclosing class.
2 - they are useful for interface implementations that are only used by the enclosing class (event handlers in a application)
3 - they are useful for providing fine grained access and creation control over an interface implementation that is retrieved externally (maybe something like an Iterator implementation)
Once you learn how to use them effectively you will wonder what you did without them.
Hope this helps.


- Chris Stehno, SCPJ
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You're likely to stumble upon a few good past conversations on inner classes when trying a search on one of the Java in General forums or the OO forum.
Note that the search page link is at the top right of this page.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Advantages of inner classes