[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


VB.NET - Inheritance - How do I use a parent constructor from within a child constructor?

Posted on 2009-02-23
Medium Priority
Last Modified: 2012-05-06
How do I use a parent constructor from within a child constructor?

public class A
dim MyInt as integer
  public sub New(byval i as integer)
    MyInt = i
  end sub
end class

public class B
  inherits A
  dim MyFloat as single
  public sub New(byval i as integer)
    ' <---- I'd like to call the parent constructor here
   MyFloat = i
  end sub
end class
Question by:hamlin11
1 Comment

Accepted Solution

hamlin11 earned 0 total points
ID: 23716044
Great question!

Class AA
    Protected Vertices() As Integer
    Public Sub New()
        Console.WriteLine("AA constructor")
    End Sub
End Class

Class BB
    Inherits AA
    Shadows Vertices() As Int64
    Public Sub New()
        Console.WriteLine("BB constructor")
    End Sub
End Class

The compiler will auto-insert a call to the no-argument constructor of a parent, otherwise you can specify on the first line of the child constructor a call to a specific parent constructor.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question