Information Technology Reference
In-Depth Information
Public Member Accessibility
The
public
access level is the least restrictive. All classes both inside and outside the assembly
have free access to the member. Figure 7-16 illustrates the accessibility of a
public
class mem-
ber of
MyClass
.
To declare a member public, use the
public
access modifier, as shown.
Keyword
↓
public int MyMember1;
Figure 7-16.
Public member accessibility
Private Member Accessibility
The
private
access level is the most restrictive.
A
private
class member can be accessed only by members of its own class. It cannot be
accessed by other classes, including classes that are derived from it.
A private member can, however, be accessed by members of classes nested in its class.
Nested classes
are covered in Chapter 23.
Figure 7-17 illustrates the accessibility of a private member.
Figure 7-17.
Private member accessibility