jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes can we declare private constructor in  servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can we declare private constructor in  servlet" Watch "can we declare private constructor in  servlet" New topic
Author

can we declare private constructor in servlet

rehans oberoi
Ranch Hand

Joined: Dec 06, 2005
Posts: 174
hi
can we declare private constructore in servlet , what would
be the answer.

thanks
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You can, but there would be little point since it would not be called by the container when loading the Servlet, and in doing so you may prevent the no-arg constructor from being called and stop the Servlet from being initialised at all.

The short answer is: not in any meaningful sense, no.
rehans oberoi
Ranch Hand

Joined: Dec 06, 2005
Posts: 174
recently this question was asked in two interviews.
how can i convince them by saying no.
[ February 19, 2006: Message edited by: rehans oberoi ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Well you don't convince them, you provide reasoning. If you need more information, we have discussed constructors in servlets a few times, such as here.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can we declare private constructor in servlet
 
Similar Threads
Private Constructor
Servlet
thread safe static variables
why we cann't make a class private and protected
Servlet init()