difference between ME and MYCLASS

R

Radu

Hi. I have the following question:

Since the methods are virtual, the following code produces "Child other
stuff" - the call runs as if pasted in Child... it runs in Parent but in the
context of Child.
-------------------------------
Module Module1

Sub Main()
Dim obj As New Child()
obj.DoSomething()
End Sub

End Module
-------------------------------
Public Class Parent

Public Sub DoSomething()
OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------
Public Class Child
Inherits Parent

Public Overrides Sub OtherStuff()
MsgBox("Child other stuff")
End Sub

End Class
----------------------------------

Therefore, to avoid this, we have to change parent using MYCLASS....

-------------------------------
Public Class Parent

Public Sub DoSomething()
MyClass.OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------

I'm confused as to what exactly is the difference between ME and MYCLASS -
why doesn't ME work in this case ? ME should refer to the current object,
(Parent, in this case), correct ?

Thank you.
Alex.
 
L

Larry Lard

Radu said:
Hi. I have the following question:

Since the methods are virtual, the following code produces "Child other
stuff" - the call runs as if pasted in Child... it runs in Parent but in the
context of Child.
-------------------------------
Module Module1

Sub Main()
Dim obj As New Child()
obj.DoSomething()
End Sub

End Module
-------------------------------
Public Class Parent

Public Sub DoSomething()
OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------
Public Class Child
Inherits Parent

Public Overrides Sub OtherStuff()
MsgBox("Child other stuff")
End Sub

End Class
----------------------------------

Therefore, to avoid this, we have to change parent using MYCLASS....

-------------------------------
Public Class Parent

Public Sub DoSomething()
MyClass.OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------

I'm confused as to what exactly is the difference between ME and MYCLASS -
why doesn't ME work in this case ? ME should refer to the current object,
(Parent, in this case), correct ?

Me does refer to the current object - the object in question (obj) is a
Child! What you are seeing is overriding working as intended...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top