August 2001
Intermediate to advanced
656 pages
18h 5m
English
Shadows Keyword
Shadows
Indicates that a derived class member is hidden if its class is assigned to an instance of its base class. Calls to the shadowed method when made through the base class see the base class implementation rather than the shadowed implementation.
Public Class Employee
Protected strName As String
Public Overridable Property Name( ) As String
Get
Name = strName
End Get
Set
strName = Value
End Set
End Property
End Class
Public Class Attorney
Inherits Employee
Public Overrides Property Name( ) As String
Get
If Instr(1, strName, "Esq") = 0 Then
Return strName & ", Esq."
Else
Return strName
End If
End Get
Set
If Instr(1, Value, "Esq") = 0 Then
strName = Value & ", Esq."
Else
strName = Value
End If
End Set
End Property
End Class
Public Class Partner
Inherits Attorney
Public Shadows Property Name( ) As String
Get
If Instr(1, strName, "Partner") = 0 Then
Return strName & ", Partner"
Else
Return strName
End If
End Get
Set
strName = Value
End Set
End Property
End Class
Module modMain
Public Sub Main
Dim oEmp As New Employee
oEmp.Name = "Jon"
Console.WriteLine(oEmp.Name)
Dim oAtt As New Attorney
Dim oEmp2 As Employee
oAtt.Name = "John"
Console.WriteLine(oAtt.Name)
oEmp2 = oAtt
Console.WriteLine(oEmp2.Name)
Dim oPart As New Partner
Dim oAtt2 As Attorney
oPart.Name = "Jack"
Console.WriteLine(oPart.Name)
oAtt2 = oPart
Console.WriteLine(oAtt2.Name)
End Sub
End ModuleThe Shadows keyword is new to VB .NET.
Read now
Unlock full access