Protected Keyword

   
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

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net