Re: void method()
On Nov 7, 3:26 am, "Crouchez" <safdfa...@asdfasdfs.com> wrote:
"Patricia Shanahan" <p...@acm.org> wrote in message
news:13j37sd3tc22tf3@corp.supernews.com...> Crouchez wrote:
Is a plain "void method()" public, protected or private by default?
No. Unfortunately, Sun chose not to allow use of a keyword for the
fourth access mode, "default access", which is really package access.
http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html...
so it's basically private?
No; default ("package private", as mentioned elsewhere) access exists
independently of private access. There's a useful progression of
access levels:
'private' allows access from within the same top-level class.
default allows access from anywhere private allows access, as well as
to any other class in the same package.
'protected' allows access from anywhere default allows access, as well
as from any subclass.
'public' allows access from anywhere protected allows access, as well
as from anywhere else. (Ok, that one's a little contrived.)
For the java.lang.ThreadGroup class, other classes in java.lang are
allowed to manipulate its default-access members; since you can only
add classes to this package via vendor-specific trickery (and you
shouldn't do that), you can treat it as an implementation detail and
pretend it doesn't exist. On the other hand, you can use default
access in your own packages to allow closely-related classes (like a
container and its iterator) to directly access one another's members,
if that's the cleanest way to implement something.