Information Technology Reference
In-Depth Information
Figure 23-9.
Accessibility between nested type members and enclosing type members
You can summarize this relationship as follows:
The members of a nested type always have full access-rights to members of the enclos-
ing type.
The members of an enclosing type
-
Always have access to the nested type itself
-
Only have the
declared access-rights
to
members
of the nested type
The visibility of nested types can also affect the inheritance of base members. If the enclos-
ing class is a derived class, a nested type can hide a base class member with the same name.
Use the
new
modifier with the declaration of the nested class to make the hiding explicit.
A
this
reference within a nested type refers to the
object of the nested type
—not the object
of the enclosing type. If an object of the nested type needs access to the enclosing type, it must
have a reference to it. You can have the enclosing object supply its
this
reference as a parame-
ter to the nested type's constructor, as shown in the following code.