Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
how to prevent to creating a object of class without its make abstract class,static class,and private constructor.
Posted
Comments
CPallini 14-Jan-12 12:52pm    
Uhm, Does hiding the source count?
Sergey Alexandrovich Kryukov 14-Jan-12 23:50pm    
What, is that an interview question or what? Why doing so?
--SA
Sergey Alexandrovich Kryukov 14-Jan-12 23:57pm    
Please do everyone a favor: don't post your questions, comments, etc. using "Add a solution". This kind of post is reserved for answers and solutions. Instead, use "Improve question", add comments, reply to other comments.
--SA
BillWoodruff 15-Jan-12 0:54am    
This question just does not make sense to me: what would be the purpose of a Class definition that was never instantiated ?

If you are asking about how to allow the creation of one and only one Class (that is not, obviously, static), then the question you are asking is how to create a "Singleton:" and there are many resources on CP to answer that question.

1 solution

I can see just one more way to achieve that, a pathological one: define all (non-private) constructors the way they always throw an exception.

I just want to tell that this question is a cheap exercise. It resembles one of those pointless interview questions some like to invent. In my opinion, it has little to do with real knowledge. I would happily work with someone who would not be able to answer this question correctly but show some deep thinking and real understanding of things.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900