| Author |
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)?? Thanks
|
Regards,<br />Andrea<br /> <br /><a href="http://www.linkedin.com/in/andreagazzarini" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID : a.gazzarini@gmail.com<br /><a href="http://www.andreagazzarini.blogspot.com" target="_blank" rel="nofollow">My Blog</a>
|
 |
Junilu Lacar
Bartender
Joined: Feb 26, 2001
Posts: 4118
|
|
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] [MiH]
|
 |
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(){} ...... ......XXX ...} } 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?? Thanks
|
 |
William Barnes
Ranch Hand
Joined: Mar 16, 2001
Posts: 965
|
|
|
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
Sheriff
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]
|
 |
 |
|
|
subject: inner class question...
|
|
|