Java Reference
In-Depth Information
voke the
getX
method of class
Point
for an instance of class
RealPoint
from outside the
body of
RealPoint
, no matter what the type of the variable we may use to hold the ref-
erence to the object. Thus, we see that fields and methods behave differently: hiding
is different from overriding.
8.5. Member Type Declarations
A
member class
is a class whose declaration is directly enclosed in another class or inter-
face declaration.
A
member interface
is an interface whose declaration is directly enclosed in another class
or interface declaration.
It is a compile-time error if a member type declaration has more than one of the access
modifiers
public
,
protected
, and
private
.
member declaration.
If a class declares a member type with a certain name, then the declaration of that type is
said to
hide
any and all accessible declarations of member types with the same name in su-
perclasses and superinterfaces of the class.
In this respect, hiding of member types is similar to hiding of fields (§
8.3
).
A class inherits from its direct superclass and direct superinterfaces all the non-
private
mem-
ber types of the superclass and superinterfaces that are both accessible to code in the class
and not hidden by a declaration in the class.
A class may inherit two or more type declarations with the same name, either from two in-
terfaces or from its superclass and an interface. It is a compile-time error to attempt to refer
to any ambiguously inherited class or interface by its simple name.
If the same type declaration is inherited from an interface by multiple paths, the class or
interface is considered to be inherited only once. It may be referred to by its simple name
without ambiguity.