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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:47:40+00:00 2026-06-07T21:47:40+00:00

What is the difference between a public abstract class with a public constructor, and

  • 0

What is the difference between a public abstract class with a public constructor, and a public class with a protected constructor. We don’t have any functions that are abstract in our abstract class, but we want programmers to only be capable of creating objects that extend that class.

Both scenarios compile and work, however I don’t understand which would be better to use in what scenario. I have been brought up to understand that although you cannot instantiate an abstract class directly (only through a non abstract child class), the abstract class should normally contain abstract functions that are required to be implemented by the children of that class.

Wouldn’t having a protected constructor in a public class signify that instantiation of this class is not possible (this is the only constructor we have).

  • 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-07T21:47:43+00:00Added an answer on June 7, 2026 at 9:47 pm

    MSDN states about using the abstract keyword for classes: Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. That is, it is not required that an abstract class contain any abstract members. The abstract modifier is just an explicit way to say that the class shouldn’t be instantiated, rather than with technical obstacles such as making constructors publicly invisible.

    Note that the technical obstacle you described even has a caveat: It can still be called:

    • It can be invoked from derived classes.
    • It can be invoked by using reflection.

    Both mean that other developers who are just (ab-?)using your class can do something you did not intend to happen, namely instantiate your class, and both are not possibly when making the class abstract.

    Therefore, the answer is that you should mark your classes as abstract.

    Note that it is adviseable to make the constructor of your abstract class protected nonetheless (to emphasize that the class cannot be instantiated). Tools such as FxCop will output a warning if an abstract class has a public constructor.

    This complies with the general rule of making each member just as visible as it really needs to be. In an abstract class, constructors will never be invoked from public scope, so public visibility is not required. They will only ever be invoked by constructors of derived classes, so protected is the reasonable visiblity for any constructors in an abstract class.

    Hence, also make any constructors of your abstract classes (at most) protected.

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

Sidebar

Related Questions

My first question: What is the difference between an protected and a public constructor
I have a relationship between two base classes: public abstract class RecruiterBase<T> { //
I have the following code snippet: public abstract class Foo { protected Foo() }
This question is out of curiosity. Is there a difference between: public abstract class
This question is out of curiosity. Is there a difference between: public abstract class
Is there any difference between: public ActionResult logOff() { FormsAuth.SignOut(); return RedirectToAction(index, Home); }
What are the difference between a public class member class data { public: std::list<data>
what would be the difference between this class Class1 { public string prop1 {
I'm learning the difference between these to concepts. I want to build a public
Is there a functional difference between the following syntax... [Foo, Bar] public class Baz

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.