File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Nested classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Nested classes" Watch "Nested classes" New topic

Nested classes

Stephen Adams

Joined: Mar 18, 2002
Posts: 22
This is my first time posting on JavaRanch, great site by the way.
My question is about Nested Classes, I know what they are and how they are created, but why would you used them instead of creating a new SubClass?
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Bruce Eckel has an interesting discussion on inner classes. According to him, inner classes allow you to hide a class that implements an interface.
You can also use an inner class if you want to create a class "on the fly".
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Also, an instance of an inner class would have access to the private members of the enclosing class. An instance of a subclass would not have access to the private members of the superclass instance.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Nested classes
It's not a secret anymore!