| Author: Ravichandran 09 Jun 2008 | Member Level: Gold | Rating: Points: 2 |
Public Class Parent
Public x As Integer = 10
End Class
Public Class Child
Inherits Parent
Public x As Integer = 20
End Class
I defined two classes, "Parent" and "Child," where "Child" gets inherited from "Parent." If I create an object (instance) with respect to "Parent" and access the field (x) as follows, there is no doubt that it displays "10."
Dim obj As New Parent
MessageBox.Show(obj.x)
However, if I create an object with respect to "Child" and access the field (x) as follows, the confusion starts:
Dim obj As New Child
MessageBox.Show(obj.x)
The class "Child" is equipped with the same field (x) twice -- one inherited from "Parent" and one of its own. If such a situation occurs, the field in the "child" shadows the field in "parent." In other words, the child member temporarily hides the parent member and activates its own. This is called shadowing.
|
| Author: Binu Appukuttan 09 Jun 2008 | Member Level: Gold | Rating: Points: 2 |
When two elements in a program have same name, one of them can hide and shadow the other one. So in such cases the element which shadowed the main element is referenced. Below is a sample code, there are two classes “ClsParent” and “ClsShadowedParent”. In “ClsParent” there is a variable “x” which is a integer. “ClsShadowedParent” overrides “ClsParent” and shadows the “x” variable to a string.
example
Public Class ClsParent Public x As Integer End Class Public Class ClsShadowedParent Inherits ClsParent Public Shadows x As String End Class
|
| Author: asdf 12 Aug 2008 | Member Level: Silver | Rating: Points: 0 |
• Shadowing It won’t replace existing methods. But replace the variations. It leaves subclass as single version of the method.
|
| Author: Satyanarayan SushilKumar Bajoria 21 Sep 2008 | Member Level: Diamond | Rating: Points: 5 |
Hi,
Shadowing: When two elements in a program have the same name,one of them can hide and shadow the other one.So in such cases the element which shadowed the main element is referenced.
For example:
public class ClsParent public x as Integer End class public class ClsShadowedParent inherits ClsParent public shadows x as string End class
Regards S.S.Bajoria
|