Can a class have a private constructor?

Posted by Im4uonli under Others on 3/16/2009 | Views : 4039 | Status : [Member] | Replies : 7
Yes, A class can have a private constructor but other classes can not instantiate the class using that constructor.




Responses

Posted by: Vuyiswamb on: 3/16/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down

What is the Purpose of what you are doing ?

Thank you for posting at Dotnetfunda
[Administrator]

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thulanekhz on: 3/16/2009 [Member] Starter

Up
0
Down
Why are you wasting IIS resources, you ask a question then answer yourself. The purpose of this forum is to learn and not play

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/16/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Easy Thulane don't Fight.

Mybe he made a mistake

Thank you for posting at Dotnetfunda
[Administrator]

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Poster on: 3/16/2009 [Member] Starter

Up
0
Down
Dear im4uonli,

May we suggest to spread your knowledge in the Interview section or Codes section.

I think those sections are made for that purpose and that will help everyone to find them easily.

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Im4uonli on: 3/16/2009 [Member] Starter

Up
0
Down
My dear Thulane and all, Don't get excited, and if you have more knowledge then share it.
I also want to know that, if no other class can create an object using this constructor, then why this feature is provided at all.
I hope U will get the point.

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/16/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Dear Im4uonli

Thulane and all were harsh to you, We apologise for that. But Please before you post make sure that we will understand what you have posted. Secondly please do not post contents that would have been posted Code in the Forums.

Well you can instantiate the Constructor if its Private.

Thank you for posting at Dotnetfunda
[Administrator]

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Poster on: 3/17/2009 [Member] Starter

Up
0
Down
Dear Im4uonli,

There is use of Private constructor when you are working with design pattern. Like if you want to work on Singleton design pattern you will have to use Private constructor to ensure that only one instance of the object exists.

For more details on this see http://www.dotnetfunda.com/articles/article69.aspx

On another note, I think the content of your post in starting of this thread confused everyone. That doesn't look like a question, it seems you tried to answer your question thats why everyone got confused.

Thanks

Im4uonli, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response