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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:43:42+00:00 2026-05-14T06:43:42+00:00

I heard that a private constructor prevents object creation from the outside world. When

  • 0

I heard that a private constructor prevents object creation from the outside world.

When I have a code

public class Product
{
   public string Name { get;set;}
   public double Price {get;set;}
   Product()
   {
   }

   public Product(string _name,double _price)
   {
   }
}

Here I still can declare a public constructor (parameter), won’t it spoil the purpose of the private constructor? When do we need both private and public constructor (parameter) in code?

I need a detailed explanation please.

  • 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-05-14T06:43:42+00:00Added an answer on May 14, 2026 at 6:43 am

    The reason you would use the pattern you’re describing is when you want to control how the object is instantiated.

    In your example, for instance, you’re saying the only way to create a Product is by specifying its name and price. This is with respect to the outside world, of course. You could also do something similar using other access modifiers, and it would have different implications, but it all boils down to controlling how you want the objects instantiated with respect to who will be doing it.

    If you wanted to prevent object creation altogether you would have to make all your constructors private (or protected). That would force the object to be created from within itself (or an inherited class).

    Also, as Matti pointed out in the comment below, when you define a constructor that is parameterized you don’t need to specify a private default constructor. At that point it is implied.

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

Sidebar

Related Questions

I heard that decision tables in relational database have been researched a lot in
I heard that on Windows you can login from a web browser to the
I've always heard that in C you have to really watch how you manage
I heard that if you use port 443 (the port usually used for https)
I heard that you could right-shift a number by .5 instead of using Math.floor().
I heard that Visual Studio came with an Image Library, but I can't find
I heard that AS boxes and un-boxes values every time arguments are passed into/out
I heard that some people where having problems accessing their sites which get their
Anyone heard that it's possible to login to Windows xp programmatically, I want to
I've heard that unit testing is totally awesome, really cool and all manner of

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.