[5638] in java-interest

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

Re: Protected Variables' "Caveat" - Misrepresented?

daemon@ATHENA.MIT.EDU (Jim.Graham@Eng.Sun.COM)
Tue Feb 20 20:49:53 1996

Date: Tue, 20 Feb 1996 15:10:10 -0800
To: java-interest@java.Eng.Sun.COM, mikea@ai.mit.edu
From: Jim.Graham@Eng.Sun.COM


> >          If a class is both a subclass of and in the same package as 
> >the class with  the protected variable, then the class has access to 
> >the protected variable   (its package status takes precedence over its subclass status). 
> 
> 	The first part says something that seems rather obvious.  Both
> subclasses AND members of the same package have access to protected
> variables.  Being both shouldn't limit the variables that a given
> class can access.
> 	What it in parenthesis thefore doesn't make sense for two reasons:
> 	1.  It is illogical as a result of what I said in the last paragraph.
> 	2.  It contradicts what we saw in the Gamma example.

I think the bottom line is that protected enhances the access of a
particular field or method to allow subclasses to access it with the
condition that they only be able to access those protected methods
and fields on objects which are subclasses of themself.  The protected
keyword only expands access, it does not restrict other forms of access,
such as the public/(friendly)/private status.  Thus, a method or variable
can be accessed if it has the appropriate scope status, or if it is
protected and a subclass's method is accessing it on an appropriately
classed object.

In other words, public/(friendly)/private are orthogonal to protected.

				...jim
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

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