Access Modifiers

Access modifiers control the accessibility of types (including enumerations, structures, classes, standard modules, and delegates) and type members (including methods, constructors, events, constants, fields [data members], and properties) to other program elements. They are part of the declarations of types and type members. In the following code fragment, for example, the keywords Public and Private are access modifiers:

Public Class SomeClass
 
   Public Sub DoSomething(  )
      ' ...
   End Sub
 
   Private Sub InternalHelperSub(  )
      ' ...
   End Sub
   
End Class

The complete list of access modifiers and their meanings is shown in Table 2-5.

Table 2-5. Access modifiers

Access modifier

Description

Friend

Defines a type that is accessible only from within the program in which it is declared.

Private

Defines a type that is accessible only from within the context in which it is declared. For instance, a Private variable declared within a class module is accessible only from within that class module. A Private class is accessible only from classes within which it is nested.

Protected

Applies to class members only. Defines a type that is accessible only from within its own class or from a derived class.

Protected Friend

Defines a type that is accessible from within the program in which it is declared as well as from derived classes.

Public

Defines a type that is publicly accessible. For example, a public method of a class can be accessed from any program that instantiates ...

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.