Thursday, October 20, 2005

Re: New kid in the block


Hi Riti,

I there is no problem in declaring / defining the constructor in
private. There is no compilation error. The problem is you will not be
able to instantiate the object of the class with private constructor.
In this case you must have some public method that can call the
constructor and return the newly created object to the caller. For eg.
Singleton Pattern. So the error you are talking about is I think with
instantiation not with the declaration/definition.

look at some code for singleton pattern and all the things will be
clear to you.

Hope it answers your query...

Regards,
BhupinderSingh.

rits wrote:
> bhupinder i have read that u cannot declare the constructors in
> private.it means the compiler will always give error even when u
> declare the constructor in private even if there is no
> inheritance.please check if i am correct.

0 Comments:

Post a Comment

<< Home