Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested classes

 
Stephen Adams
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic