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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:58:50+00:00 2026-06-04T21:58:50+00:00

I have an asbtract class Example. Another generic class UsesExample uses it as a

  • 0

I have an asbtract class Example. Another generic class UsesExample uses it as a constraint, with a new() constraint. Later, I create a child to Example class, ExampleChild, and use it with generic class. But somehow when the code in generic class tries to create new copy, it invokes not the constructor in the child class, but the constructor in the parent class. Why does it happen?
Here’s the code:

abstract class Example {

    public Example() {
        throw new NotImplementedException ("You must implement it in the subclass!");
    }

}

class ExampleChild : Example {

    public ExampleChild() {
        // here's the code that I want to be invoken
    }

}

class UsesExample<T> where T : Example, new() {

    public doStuff() {
        new T();
    }

}

class MainClass {

    public static void Main(string[] args) {

        UsesExample<ExampleChild> worker = new UsesExample<ExampleChild>();
        worker.doStuff();

    }

}
  • 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-04T21:58:54+00:00Added an answer on June 4, 2026 at 9:58 pm

    When you crate an object, all constructors are called. At first the base class constructor constructs the object so that the base members are initialized. Later the others constructors in hierarchy are called.

    This initialization may call static functions so that it makes sense to call the constructor of an abstract base class even if it has no data members.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one abstract class named contact and another class called client that inherits
I have one abstract class and many child classes. In child classes are from
I have a class that inherits a base class to which another class has
I have several classes like in the following example: abstract class AClass { boolean
I have a class - PluginLoader which deals with another class Plugin to carry
I have a base class and another derived from it. Let's assume, the base
For example, there is a class Warrior which have linked class Sword. In class
Suppose we have abstract class A (all examples in C#) public abstract class A
Let say I have abstract class called: Tenant and Customer. The tenant in this
I have abstract BaseController, which basically looks like below: public abstract class BaseController :

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.