PROTECTED variable question
Question: when to declare a variable as "PROTECTED" .
I created a class called as "Employee" and declared a variable as
Protected mFirstName.
After I instantiated an object of the type "Employee" class, I can't use the variable.
The error is "Employee.mFirstname is not accessible in this context because it is 'Protected'. It works if i change the scope of the mFirstName to 'Public'.
But according to the definitions I read in the books, 'Protected' variables can be accessed from Class or derived classes.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim clsBasam As clsFHLBEmployee
clsBasam = New clsFHLBEmployee("Basam Nath")
MsgBox("The Firsname of the basam is " & clsBasam.mFirstname)
End Sub
Public Class clsFHLBEmployee
Protected mFirstname As String
Public Property FirstName() As String
Get
Return mFirstname
End Get
Set(ByVal Value As String)
mFirstname = Value
End Set
End Property
Public Sub New(ByVal firstname As String)
'MsgBox("The constructor of the clsFHLBEmployee")
Me.FirstName = firstname
End Sub
thank you so much....so there is a difference between
Now I realized that there is a difference between 'instantiate' and 'inherit'.
I was under the impression that when you instantiate an object (of a particular class), it will inherit all the members of the class. There is truth to some extent in that statement. You will inherit all the public members only when you instantiate. But not members declared as 'PROTECTED'.
If you want to use a 'PROTECTED' member from a base class you can't use that member by instantiating an object of that class but by Inheriting from the base class.
correct?
thanks for your replies...
nath