[3481] in java-interest

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

Re: protected is not?

daemon@ATHENA.MIT.EDU (Edith Au)
Tue Nov 14 14:05:38 1995

To: Michael Daconta <daconta@PrimeNet.Com>
Date: Tue, 14 Nov 1995 10:30:04 -0500 (EST)
From: Edith Au <edith@pencom.com>
Cc: java-interest@java.sun.com
In-Reply-To: <199511132338.QAA21325@usr1.primenet.com> from "Michael Daconta" at Nov 13, 95 04:38:15 pm

Hi,

  protected variables can be accessed by the methods of its class and subclasses

apiece is an object of junk so apiece can access protected variable name.
Change name to a private variable if you want name to be accessed only by
the junk class.

Cheers,
Edith

> 
> 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.
> 
> Any ideas or is this a bug?
> 
> I am using the beta for Win95.
> 
>  - Mike Daconta
> 
> -
> This message was sent to the java-interest mailing list
> Info: send 'help' to java-interest-request@java.sun.com
==============================================================================
Edith Au                            Tel:    (212) 513 7777
WWW Specialist                      Email:  edith@pencom.com
Pencom Systems Incorporated         WWW:    http://www.pencomsi.com/~edith      
40 Fulton Street,
NY, NY 10038
===============================================================================
-
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