G
Guest
Hi
Please can someone explain this behaviour:
I have a MustInherit Base class and a Derived class that Inherits Base and
Shadows a method in the base class.
If I Dim a variable of type Derived and New it as Derived the code in the
Derived class is called. However, if I Dim the variable as type Base but New
it as type Derived the Base class code is called - I would expect the code in
the derived class to be called in all instances.
Public MustInherit Class Base
Public Sub DoSomething()
MsgBox("Base")
End Sub
End Class
Public Class Class1
Inherits Base
Public Shadows Sub DoSomething()
MsgBox("Class1")
End Sub
End Class
Dim x As Base = New Class1
x.DoSomething() ' "Base" displayed
Dim y As Class1 = New Class1
y.DoSomething() ' "Class1" displayed
Many thanks for your comments.
Julia.
Please can someone explain this behaviour:
I have a MustInherit Base class and a Derived class that Inherits Base and
Shadows a method in the base class.
If I Dim a variable of type Derived and New it as Derived the code in the
Derived class is called. However, if I Dim the variable as type Base but New
it as type Derived the Base class code is called - I would expect the code in
the derived class to be called in all instances.
Public MustInherit Class Base
Public Sub DoSomething()
MsgBox("Base")
End Sub
End Class
Public Class Class1
Inherits Base
Public Shadows Sub DoSomething()
MsgBox("Class1")
End Sub
End Class
Dim x As Base = New Class1
x.DoSomething() ' "Base" displayed
Dim y As Class1 = New Class1
y.DoSomething() ' "Class1" displayed
Many thanks for your comments.
Julia.