[Bluej-discuss] private fields of superclass in object inspector

Michael E. Caspersen mec at daimi.au.dk
Fri Dec 14 16:55:10 GMT 2007


> I don't think that it is correct that private fields are not  
> inherited.

The Java language specification is _very_ strange on this issue.

Below are the portions of the Java language spec concerning  
inheritance. This is the language spec for the third edition, which  
can be downloaded from this URL:

     http://java.sun.com/docs/books/jls/

I prefer Michael Kölling's terminology, but --unfortunately-- this is  
not the terminology of the language spec.

-- Michael


-----------------
8.2 Class Members

The members of a class type are all of the following:

* Members inherited from its direct superclass (§8.1.4), except in  
class Object, which has no direct superclass

* Members inherited from any direct superinterfaces (§8.1.5)

* Members declared in the body of the class (§8.1.6)

Members of a class that are declared private are not inherited by  
subclasses of that class. Only members of a class that are declared  
protected or public are inherited by subclasses declared in a package  
other than the one in which the class is declared.

AND LATER
A class inherits from its direct superclass and direct superinterfaces  
all the non-private fields of the superclass and superinterfaces that  
are both accessible to code in the class and not hidden by a  
declaration in the class.

Note that a private field of a superclass might be accessible to a  
subclass (for example, if both classes are members of the same class).  
Nevertheless, a private field is never inherited by a subclass

==========

12.5 Creation of New Class Instances

Whenever a new class instance is created, memory space is allocated  
for it with room for all the instance variables declared in the class  
type and all the instance variables declared in each superclass of the  
class type, including all the instance variables that may be hidden  
(§8.3).


More information about the bluej-discuss mailing list