Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class access modifiers

 
Dan Drillich
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that inner classes can be declared as public, private or protected.
How is it used? � What�s the difference in access between an inner class that is defined as private versus one which is defined as public?
Thanks,
Dan
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this forum isn't for question about Java. It is for questions and comments about JavaRanch. try one of the other forums.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to Java in General (beginning)
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The access modifiers act the same as any regular identifier. If your inner-class is public, you can create an instance of the inner-class from any other class outside of the outer-class (with the caveat that since the inner-class is not static, you must first have an instance of the outer-class). If the modifier is private, only the outer-class is able to create an instance of the inner-class, you won't be able to instantiate an object of the inner class elsewhere. Again, you must have an instance of the outer-class to do this.
See http://www.javaranch.com/campfire/StoryInner.jsp for a very nice story on inner classes
Hope this helps,
Jason
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic