[3543] in java-interest

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

Re: protected is not?

daemon@ATHENA.MIT.EDU (Michael Daconta)
Wed Nov 15 21:12:19 1995

Date: Wed, 15 Nov 1995 16:29:11 -0700 (MST)
To: Pat Niemeyer <pat@icon-stl.net>
From: daconta@PrimeNet.Com (Michael Daconta)
Cc: java-interest@java.sun.com

At 07:20 PM 11/14/95 -0600, Pat Niemeyer wrote:
>
>On Mon, 13 Nov 1995, Michael Daconta wrote:
>
>> Here is a simple chunk of code that does not
>> seem to work properly.
>> 
>> class junk {
>>         protected String name;
>> 
>>         junk(String inName)
>>         {
>>                 name = new String(inName);
>>         }
>> }
>> 
>> class Protect {
>>         public static void main(String args[])
>>         {
>>                 junk apiece = new junk("piece of junk");
>> 
>>                 System.out.println(apiece.name);
>>         }
>> }
>> 
>> 
>> This code compiles and prints out the name of the
>> object.  The problem is that the compiler should not have
>> let me do this.  name is a protected variable. protected should
>> mean that inaccesible except to subclasses.
>
>Protected members are avaiable to subclasses and classes in the same *package*
>or compilation unit.  If you put junk in a seperate package its protected 
>members will not be accessible by Protect.  
>
>I believe that this is the default permission if you don't use any modifiers.
>
>
>Pat
>
>

Hi Pat,

I hear what you are saying but that does not track with the meaning
of a Protected variable.  Essentially what you said was - it is
only "protected" outside of the package.  That would be a serious
change to the idea of access specifiers.

Also, packages are primarily a mechanism to separate namespaces.
Being in the same package should have nothing to do with permission
to access protected variables.  If that is the default, I think the
default should be changed to the same meaning as in C++.

Changing the meaning of an access specifier even in the same package
does serious damage to the concept of encapsulation and data hiding.

I'd rather hope this was a bug.  Java team?  (And the survey says...)

 - Mike Daconta

-
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