<ms****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a parent class and child class. When I execute function
ONE from child class, is it going to executes parent's code plus
child's code?
It depends. ;-)
Given these :
Class Parent
Public Sub ONE()
Debug.Writeline( "Parent.ONE" )
End Sub
End Class
Class Child
Inherits Parent
End Class
then
Dim c As New Child
c.ONE()
will display "Parent.ONE" - the child class is simply "passing on" the
Parent class' functionality.
However, changing these classes a little :
Class Parent
Public Overridable Sub ONE()
Debug.Writeline( "Parent.ONE" )
End Sub
End Class
Class Child
Inherits Parent
Public Overrides Sub ONE()
Debug.Writeline( "Child.ONE" )
End Sub
End Class
then
Dim c As New Child
c.ONE()
now displays "Child.ONE". The Child mothod replaces (a.k.a.
Overrides) the Parent method.
<--
And, just to be /really/ confusing, try this and see what you get ...
DirectCast( c, Parent ).ONE() ' ;-)
-->
To get /both/ sets of code to run, you make the Child method
call the Parent one, as in
Class Child
Inherits Parent
Public Overrides Sub ONE()
MyBase.ONE()
Debug.Writeline( "Child.ONE" )
End Sub
End Class
which (finally) displays "Parent.ONE" followed by "Child.ONE".
HTH,
Phill W.