In article <11************ **********@g14g 2000cwa.googleg roups.com>,
jw*****@gmail.c om wrote:
Is it possible to call a method from a parent object, but have the
childs overriden method called instead of the base method?
I want several children objects to all call a certain method when they
are initialized, but they all have different implementations of that
method.
thanks
Two things... If your talking about constructors - then, it doesn't
matter because constructors are not inherited. So, each child class
will have it's own unique Sub New.
If your talking about a method that is called from a parent reference,
then you can do something like this:
Option Strict On
Option Explicit On
Module Module1
Sub Main()
Dim p As Parent
p = New Child1
p.Method()
p = New Child2
p.Method()
p = New Child3
p.Method()
End Sub
Private MustInherit Class Parent
Public MustOverride Sub Method()
End Class
Private Class Child1
Inherits Parent
Public Overrides Sub Method()
Console.WriteLi ne("Child1")
End Sub
End Class
Private Class Child2
Inherits Parent
Public Overrides Sub Method()
Console.WriteLi ne("Child3")
End Sub
End Class
Private Class Child3
Inherits Parent
Public Overrides Sub Method()
Console.WriteLi ne("Child3")
End Sub
End Class
End Module
If none of this actually answers your question... Hopefully someone
else will understand what your asking better :) Or, you can post some
air-code that sort of shows off what you're trying to do.
--
Tom Shelton [MVP]