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 8122209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:45:28+00:00 2026-06-06T05:45:28+00:00

I have two classes, one that inherits from the other. The base class is

  • 0

I have two classes, one that inherits from the other. The base class is MustInherit/abstract and defines a MustOverride/abstract property.

As part of the base classes initialization, it sets a variable based on the value of the abstract property. The problem is that the inheriting class accepts as its parameter the value which should be assigned to the overriden property. The inherited class sets this property, but not before calling the base class’ initializer.

Basically, I need to initialize part of the base class, then allow the inheriting class to initialize some of its properties, then return to the base class to finish initializing more properties.

I would make the property part of the base class, but the inheriting classes employ strong typing whereas the base class only needs an interface.

Code example:

MustInherit Class A
  MustOverride Property X As IExample

  Sub New()
    ' Do some stuff
    _privateY = X.Foo() ' NullReferenceException
  End Sub
End Class

Class B
  Inherits A

  Override Property X As IExample ' returns StrongX
  Property StrongX As ConcreteExample ' ConcreteExample implements IExample

  Sub New(x As ConcreteExample)
    MyBase.New(x)
    StrongX = x
  End Sub
End Class
  • 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-06T05:45:29+00:00Added an answer on June 6, 2026 at 5:45 am

    It is exactly for this reason that abstract members should not be called in the constructor. http://msdn.microsoft.com/en-us/library/ms182331(v=vs.100).aspx

    If you have control of the abstract class I would suggest passing the value in through the base class constructor.

    public abstract class A
    {
        public A(IExample x)
        {
            // Do Stuff
            var _privateY = x.Foo();
        }
    }
    
    public class B : A
    {
        public B(IExample x):base(x)    {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains objects of two other classes. I need one
I have two classes one of which inherits from the other. Im trying to
I have a class that instantiates two classes which implement interfaces. I want one
VB.NET 2008 .NET 3.5 I have two base classes that are MustInherit (partial). Let's
Note: This is a homework assignment. I have two classes, one inherits from the
I've got two classes: a template class, and a regular class that inherits from
I have two objects that are derived from same the base class. Lets say
I have created two viewController classes such that one is superclass of another.i have
I have two classes, one uses selenium to browse the internet, and the other
I have two classes evaluated threads but I cannot send a signal from one

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.