J
Joe HM
Hello -
I have a question regarding overloading the New() in a MustInherit
Class. The following show the code in question ...
MustInherit Class cAbstract
Public MustOverride Sub print()
Protected mName As String
Public Sub New() ' Why do I have to override this?
mName = "N/A"
End Sub
Public Sub New(ByVal aName As String)
mName = aName
End Sub
End Class
Class cChildOfAbstract
Inherits cAbstract
Public Overrides Sub print()
Console.WriteLine("cChildOfAbstract.print() > mName = '" &
mName & "'")
End Sub
End Class
....
Dim lInstanceOfChild As New cChildOfAbstract("My Name") ' Why is
this not working?
....
First of all, I have to override the New(). Is this because I
overloaded it with the New(ByVal aName As String)?
Then I'm trying to call the overloaded constructor when I instantiate
the cChildOfAbstract but I cannot do that because apparently I have
too many arguments. This works if I override the New(ByVal aName As
String) in the child class but why do I have to do that? I thought I
would inherit that from the base class.
Thanks!
Joe
I have a question regarding overloading the New() in a MustInherit
Class. The following show the code in question ...
MustInherit Class cAbstract
Public MustOverride Sub print()
Protected mName As String
Public Sub New() ' Why do I have to override this?
mName = "N/A"
End Sub
Public Sub New(ByVal aName As String)
mName = aName
End Sub
End Class
Class cChildOfAbstract
Inherits cAbstract
Public Overrides Sub print()
Console.WriteLine("cChildOfAbstract.print() > mName = '" &
mName & "'")
End Sub
End Class
....
Dim lInstanceOfChild As New cChildOfAbstract("My Name") ' Why is
this not working?
....
First of all, I have to override the New(). Is this because I
overloaded it with the New(ByVal aName As String)?
Then I'm trying to call the overloaded constructor when I instantiate
the cChildOfAbstract but I cannot do that because apparently I have
too many arguments. This works if I override the New(ByVal aName As
String) in the child class but why do I have to do that? I thought I
would inherit that from the base class.
Thanks!
Joe