R
Roedy Green
... and its inner classes. Or is that what you mean with "inside
the body"?
they get complicated. See
http://mindprod.com/jgloss/nestedclasses.html
... and its inner classes. Or is that what you mean with "inside
the body"?
So if a plain method (ie. void method()) is part of a class in the Sun JDK
it's basically private?
Is a plain "void method()" public, protected or private by default?
Lothar said:... and its inner classes. Or is that what you mean with "inside
the body"?
void add(Thread t) is a method in ThreadGroup that has default (or
package private) access. This mean that classes in java.lang can access
this method (because it is package private) however as you are unable to
'add' classes to the java.lang package you can't access this method
from your third party app. Actually in Eclipse you can write and compile
a class in the java.lang package but if you try to run it you get
java.lang.SecurityException: Prohibited package name: java.lang which is
interesting... gosh, it's been a while since I did the security thing.
Roedy Green said:Your question implies you have big hole in your knowledge. It will
take a long time to fill it by asking individual questions on a
newsgroup. Instead get a text book and read up on scope. Then ask
questions about what still does not make sense.
You can also read my more informal essays on scope.
Start at http://mindprod.com/jgloss/scope.html
and follow the links.
I recall wrestling with this long ago, doing experiments, and finally
deciding it was all trivial and obvious. Oddly, I have yet to figure
out a way to explain it all that makes its obviousness immediately
apparent.
Have faith that you will have some aha moments and you will wonder
what all the fuss as about.
Anonymous classes are another matter.
Well the package private is barely ever used and I'd say 99% of methods have
a named access modifier
Crouchez said:Is a plain "void method()" public, protected or private by default?
Adam said:None of the above. It is 'default.'
True.
Its visibility is restricted to classes in the current package,
and subclasses in other packages.
I've just released what package private actually is - it's the old basic
method (like in many old procedural languages) that didn't include method
security - limited to the working folder.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.