It's not a secret anymore!
The moose likes Beginning Java and the fly likes Inner class access modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inner class access modifiers" Watch "Inner class access modifiers" New topic

Inner class access modifiers

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
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?

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
this forum isn't for question about Java. It is for questions and comments about JavaRanch. try one of the other forums.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
I'm moving this to Java in General (beginning)

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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 for a very nice story on inner classes
Hope this helps,
I agree. Here's the link:
subject: Inner class access modifiers
It's not a secret anymore!