Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

Protected Keyword

Description

Used to declare classes and their members.

When the 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 Private; that is, it can only be accessed within the declaring class. (See the upcoming example.)

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).

Example

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"

VB.NET/VB 6 Differences

The Protected keyword is new to VB.NET.

See Also

Friend Keyword

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata