Unexpected behaviour of MyClass (please ignore 1st post)

  • Thread starter Thread starter Diana Mueller
  • Start date Start date
D

Diana Mueller

Public Class Base
Public Function Foo() As String
Return MyClass.GetType.FullName
End Function

End Class

Public Class Derrived
Inherits Base
End Class

Why does Derrived.Foo() return "Derrived"? Shouldn't that be "Base"?
 
Diana Mueller said:
Public Class Base
Public Function Foo() As String
Return MyClass.GetType.FullName
End Function

End Class

Public Class Derrived
Inherits Base
End Class

Why does Derrived.Foo() return "Derrived"? Shouldn't that be "Base"?

If you instantiate 'Derived' and call 'Foo' on this object, the object's
most specific type is 'Derived', and thus "Derived" is returned.
 
Diana,

Because you are doing a methnod which is in MyClass which returns the type
of the current instance and not from the used class

Than it would have been
Gettype(Base).FullName

I hope this helps,

Cor
 

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

Back
Top