Thursday, 17 June 2010

SHADOWING

When global and local varible in the same name.
the local varibale in a mehod or function which use to
override the global is called the shadowing.
ie the Global varible is being shadowed by the
local varible


Public Class Clsparent
Public x As String = 7

End Class

Public Class ClsShadowedparent
Inherits Clsparent
Public Shadows x As String = "dgfdg"

Sub kotha()
Dim k As Integer = MyBase.x
Dim kk As String = Me.x
End Sub
End Class



button_click :
============

Dim ksf As New ClsShadowedparent
ksf.kotha()




Thre are few differences between those.
1. Shadowing is bad programming practice according to OOPs concepts.
2. In shadowing signature could be different.
3. In Shadowing both Derived class methods and Base Class methods are available for use.(So its a bad practice)

No comments:

Post a Comment