Override MustOveride String property in MustInherit class error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a Mustinherit class with two must override readonly properties:

Public MustInherit Class RequestPart
Public MustOverride ReadOnly Property Description() As Boolean
Public MustOverride ReadOnly Property Mandatory() As String
End Class

I the derived class I cannot override the property Mandatory because the
return types differ:

Public Class Login
Inherits RequestPart
Private _Username As String
Private _Password As String
Private _Description As String
Public ReadOnly Property Description() As String
Get
Return _Description
End Get
End Property

Public ReadOnly Property Mandatatory() As Boolean
Get
Return True
End Get
End Property
and so on....

Why do I get the error that the return types differ?
 
Why do I get the error that the return types differ?

Because the return types differ.

When you override a function, you must use the same signature as the
function you are overriding. Otherwise you are overloading, which cannot
differ ONLY by return type.
 
You have the return types inverted

Base
- Description => Boolean
- Mandatory => String

Derived
- Description => String
- Mandatory => Boolean


hth,
Alan.
 
In RequestPart, Description is Boolean, Mandatory is String.
In Login, Description is String, Mandatory is Boolean.

I guess you simply mixed them up in RequestPart class.

Also, in Login Class overrided properties should be marked as Overrides;
see example:

~
Public MustInherit Class RequestPart
Public MustOverride ReadOnly Property Description() As String
Public MustOverride ReadOnly Property Mandatory() As Boolean
End Class

Public Class Login
Inherits RequestPart
Private _Username As String
Private _Password As String
Private _Description As String
Public Overrides ReadOnly Property Description() As String
Get
Return _Description
End Get
End Property

Public Overrides ReadOnly Property Mandatory() As Boolean
Get
Return True
End Get
End Property
End Class
~

Roman
 
Back
Top