Override MustOveride String property in MustInherit class error


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?
 
Ad

Advertisements

R

Rick Mogstad

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.
 
A

alantolan

You have the return types inverted

Base
- Description => Boolean
- Mandatory => String

Derived
- Description => String
- Mandatory => Boolean


hth,
Alan.
 
Ad

Advertisements

D

Dragon

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
 

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