[197] in java-interest

home help back first fref pref prev next nref lref last post

Re: non-public classes in packages

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Mon Jun 5 20:55:03 1995

Date: Mon, 5 Jun 1995 16:47:27 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: java-interest@java.Eng.Sun.COM

Hi,

>   A private class should not be visible or accessible outside the package. 
> 
>   However, a private method or instance variable is visible but not accessible
>   outside the class.     Arthur van Hoff (avh@eng.sun.com)
> 
> I've already reported the JavaSpec.'s lack of any definition for a private
> class (or interface), but since the above appears to define it for me, am
> I now to assume that the default case is identical to private, i.e., that:
> 
> 	class C ...
> and
> 	private class C ...
> 
> both limit the class's visibility and access to the current package?  And
> is the same true for interfaces?

Yes. Private is the default. Actually, you are not supposed to use the
"private" modifier because it is confusing. A private class does not
mean: it can only be accessed by this class (unlike private variables
an methods). Instead it means: it can only be accessed from this
package.

The class is still visible outside the package. However, the compiler
should not complain if there is an ambiguity between a public and a
private class (it should use the public one, I think that is currently
broken).

> Also, if private variables and methods are visible outside the package,
> they still pollute the namespace of any package that imports them!?!  Is
> this really the case?  I could see "protected" wanting to act this way
> perhaps, but not private.  Arthur, can you clarify these points?

The are visible in the sense that when you try to access a private
variable or method the compiler will say "oops, that is private"
instead of "oops, that does not exist". private classes/methods/variables
should not pollute the name space.

Have fun,

	Arthur van Hoff (avh@eng.sun.com)
	http://java.sun.com/people/avh/
	Sun Microsystems Inc, M/S UPAL02-301,
	100 Hamilton Avenue, Palo Alto CA 94301, USA
	Tel: +1 415 473 7242, Fax: +1 415 473 7104

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post