|
-
May 11th, 2005, 05:20 PM
#1
Thread Starter
Hyperactive Member
Inheritance Question
When you inherit an object into a class, If you don't delcare a constructor, will it use the inherited objects constructor by default?
Code:
Public Class clsArrayList
Inherits ArrayList
Public Function ReturnTypeList(ByVal inType As Type) As ArrayList
Dim retList As New ArrayList
'Return a new list by object type
For Each o As Object In Me
If o.GetType Is inType Then retList.Add(o)
Next
Return retList
End Function
End Class
Or do I have to add these to use the default conscrutors?
Code:
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal capacity As Integer)
MyBase.New(capacity)
End Sub
Public Sub New(ByVal c As System.Collections.ICollection)
MyBase.New(c)
End Sub
Next question, I am eventually going to be Serializing this arraylist to a XML file using the XmlSerializer and from what I understand that the ArrayList object you serialize needs to Implement an IColletion interface, An arraylist does this by default, Does my class above still implement the ICollection since it's based off a ArrayList object or do I need to specify that as well?
Thanks
Hinder
-
May 11th, 2005, 05:35 PM
#2
Addicted Member
Re: Inheritance Question
Your inherited object gains the constructor and interface(s) of its parent class.
-
May 11th, 2005, 10:20 PM
#3
Re: Inheritance Question
Actually Constructors are the only thing not passed to a derived class. So it would inherit the interface but not the constructors. You can call them as you show but you will need to write that code it is not implied via inheritance.
Nevermind I guess it does inherit and fire the parent classes default constructor but it doesn't inherit any of the non default constructors.
So calling New on your child class will use the New on the parent class the same as:
VB Code:
Public Sub New()
Mybase.New()
End Sub
But the child class will not have the other constructors through inheritance.
VB Code:
Public Class Parent
Public Sub New()
MsgBox("Showing")
End Sub
Public Sub New(ByVal msg As String)
MsgBox(msg)
End Sub
End Class
Public Class Child
Inherits Parent
End Class
'syntax of use
Dim c As New Child 'only default constructor is available
Last edited by Edneeis; May 11th, 2005 at 10:26 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|