[3506] in java-interest

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

Re: protected is not?

daemon@ATHENA.MIT.EDU (Pat Niemeyer)
Tue Nov 14 22:47:52 1995

Date: Tue, 14 Nov 1995 19:20:46 -0600 (CST)
From: Pat Niemeyer <pat@icon-stl.net>
To: Michael Daconta <daconta@PrimeNet.Com>
cc: java-interest@java.sun.com
In-Reply-To: <199511132338.QAA21325@usr1.primenet.com>


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
-
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