Used to declare classes and their members.
Protected keyword is used to modify a
member declaration, the member being declared has direct access scope
to the class module in which the member is declared, as well as to
all derived classes in all projects. However, as far as object access
is concerned, the member is considered
that is, it can only be accessed within the declaring class. (See the
Declaring a class module as
Protected limits all
of the class’ members to Protected access (or
stronger if the member has further specific access restrictions).
Suppose we declare the following variable in a class module named Class1:
Protected sProtectedVar As String
Then within Class1 or any of its derived classes in any project, we can use the variable directly, as in:
Public Class Class2 Inherits Class1 Public Sub Test( ) MsgBox sProtectedVar End Sub End Class
On the other hand, the following code, located in a form module, is illegal:
Dim c as New Class1 c.sProtectedVar = "Donna"
Protected keyword is new to VB.NET.