Name

Shadows Keyword

Syntax

Shadows

Description

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.

Example

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 Module

VB .NET/VB 6 Differences

The Shadows keyword is new to VB .NET.

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.