Explain shadowing.
When two programming elements share the same name, one of them can hide — that is, shadow — the other one. In such a situation, the shadowed element is not available for reference; instead, when your code uses the shared name, the Visual Basic compiler resolves it to the shadowing element. An element can shadow another element in two different ways.
The shadowing element can be declared inside a subregion of the region containing the shadowed element, in which case the shadowing is accomplished through scope. Or a deriving class can redefine a member of a base class, in which case the shadowing is done through inheritance.
Example:
Public Class BaseCls
Public Z As Integer = 100 ' The element to be shadowed.
End Class
Public Class DervCls Inherits BaseCls
Public Shadows Z As String = "*" ' The shadowing element.
End Class
Public Class UseClasses
Dim BObj As BaseCls = New DervCls() ' DervCls widens to BaseCls.
Dim DObj As DervCls = New DervCls() ' Access through derived class.
Public Sub ShowZ()
MsgBox("Accessed through base class: " & BObj.Z) ' Outputs 100.
MsgBox("Accessed through derived class: " & DObj.Z) ' Outputs "*".
End Sub
End Class
