Re: How to make a Java class only visible inside the package & not
visible to other packages?
www wrote:
I want to make my Java class Person only visible to other classes
located in the same package, invisible to other classes in other
packages. How should I do that?
See Martin's response for this part.
Another question is: since Person is declared as "final" and is only
visible inside the package, then all the "public" methods inside Person
is not "public" anymore, they equal to "protected" methods, correct?
Not at all. A protected method can be called from any
class in the same package or from any subclass in any package
at all. By using `final' you've made subclasses impossible,
so the method can only be called from within the package.
In this case, `protected' is pointless; the method can be
called from exactly the same places that would be able to
call it if `protected' weren't there at all.
A public method, on the other hand, can be called from
any class in any package whatsoever. It doesn't matter that
`final' prohibits subclassing, because public access doesn't
need any inheritance relationship. Your Person method can
use the public length() method of the final class String,
can it not?
--
Eric.Sosman@sun.com