C
Crouchez
Is a plain "void method()" public, protected or private by default?
Crouchez said:Is a plain "void method()" public, protected or private by default?
Crouchez said:Is a plain "void method()" public, protected or private by default?
Patricia Shanahan said: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#36154
Patricia
Crouchez said:so it's basically private?
Esmond Pitt said:No, it is 'none of the above'. It means 'accessible to all classes
within the same package'. As it says in the post you quoted and the link
cited therein.
Crouchez said:So what's this ThreadGroup method available to?:
Crouchez said:so it's basically private?
Crouchez said:Is a plain "void method()" public, protected or private by default?
The default is called "package private", that is, it is only accessible
within a package.
Crouchez said:So if a plain method (ie. void method()) is part of a class in the Sun JDK
it's basically private?
Lew said:There is no "basically private" access. There are four access levels, and a
method or member's access is exactly one of the four, never "basically" any of
them.
If a method (as in your example) is declared without any access modifier, then
it has exactly package-private access. Not private. Private access means
accessible only to the class itself. Package-private is more exposed than
that; in addition, any class in the same package has access to it.
void add(Thread t) is a method in ThreadGroup that has default (orCrouchez said:I know but what I am saying is if you write a 3rd party app and create a new
java.lang.ThreadGroup you can't use it's method "void add(Thread t)"
Patricia said:A private method can only
be accessed inside the body of the top level class that encloses its
declaration.
Are said:Private allow only the one class to access,
protected allow the class
and it's subclasses access
and last, public allow any class to access.
Crouchez said:I know but what I am saying is if you write a 3rd party app and create a new
java.lang.ThreadGroup you can't use it's method "void add(Thread t)"
Is a plain "void method()" public, protected or private by default?
so it's basically private?
so it's basically private?
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.