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 inner class question... 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 question..." Watch "inner class question..." New topic

inner class question...

Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
Hi everyone!
If I have a private inner class what modifier must I assign to this class members (constructor, variables and methods)??

Regards,<br />Andrea<br /> <br /><a href="" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID :<br /><a href="" target="_blank" rel="nofollow">My Blog</a>
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Your code will still compile no matter what access modifier you use for the members. However, since it is a private inner class, only the enclosing class will have access to it and its members. So I guess it comes down to what you think expresses your intent more clearly.
Moving this to Java in General (Beginner)

Junilu - [How to Ask Questions] [How to Answer Questions]
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
What I would know is :
If I have a private Inner class like this:
public Outer{
...private class Inner{
......XXX String aVariable;
......XXX Inner(){}
......XXX void doSomething(){}

what is the correct modifier to assign to the members (in place of XXX)?
I know that every modifier compile fine, but I would know what's the better modifier (XXX = private ?)
What sense to make all modifier, for example, with default modifier??
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

I think (if I understand correctly) there isn't a 'correct' choice in this case. Since it is an inner class the only class which has access to the methods is the enclosing class. It doesn't matter if you make the methods 'public' or 'private'.

Please ignore post, I have no idea what I am talking about.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Rewording William's response a bit and merely repeating Junilu:
Since it is a private inner class the only things that have access to its members are itself and the other members of the enclosing class - no matter the access modifiers of the inner class' members.
[ October 22, 2002: Message edited by: Dirk Schreckmann ]

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