Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:49:04+00:00 2026-06-11T05:49:04+00:00

Could someone explain to me why I get a compiler error when I try

  • 0

Could someone explain to me why I get a compiler error when I try to call a base class’ constructor from an inherited object? I’ve included a brief example of what I’m referring to.

Public Class Person
    Public name As String

    Public Sub New()
        name = "John Doe"
    End Sub

    Public Sub New(Name As String)
        name = Name
    End Sub

End Class

Public Class NamedPerson
    Inherits Person

    Public Sub New(FirstName As String, LastName As String)
        name = FirstName & " " & LastName
    End Sub

    'adding this makes it work
    Public Sub New(Name As String)
       MyBase.New(Name)
    End Sub

End Class

'Valid
Dim guy1 As Person = New Person()

'Valid 
Dim guy2 As Person = New Person("John Smith")

'Valid
Dim guy3 As NamedPerson = New NamedPerson("John", "Smith")

'Compiler Error
Dim guy4 As NamedPerson = New NamedPerson("John Smith")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:49:05+00:00Added an answer on June 11, 2026 at 5:49 am

    Child classes do not inherit constructors from their base types. A child class is responsible for defining it’s own constructors. Additionally it must ensure that each constructor it defines either implicitly or explicitly calls into a base class constructor or chains to another constructor in the same type.

    For more info See: Instance Constructors

    From your sample classes,

    Public Class NamedPerson
        Inherits Person
    
        Public Sub New(Name As String)
            MyBase.New(Name)
        End Sub
    
        Public sub New(FirstName As String, LastName As String)
            name = FirstName & " " & LastName
        End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please explain why I get the potential leak of an object warning
Could someone please help explain why I can't get this to work? I properly
Could someone explain to me why this is fail. Trying to get the opacity
could someone explain me what's the idea behind using Auto-Implemented Properties c#? public class
I get a compiler error when using an Objective-C object within a switch statement:
Could someone please explain what's the difference between inheriting from ISerializable interface and declaring
Could someone explain what is wrong with this if statement? I get: lvalue required
Please could someone advise? We have an abstract base class with a few properties
Could someone explain what's wrong with this snippet? I'm looking to get the width
Could someone explain how to extract the lyrics from an mp3 file?I tried but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.