what happen if the private constructor is written in a claass

Answer Posted / diego antonio

Yes! You can!

1.- You could have serveral constructors by requesting
different parameters set: if any of them is public, you can
use it.

2.- you could have an static method (which does not need
instance of the class) named, by example,
getNewInstance(...) which internally uses the private
constructor to instance a class (as in the factory pattern),
or as in the Singleton pattern to get the only one instance
(private and static instance).

3.- If several constructors exists, the private ones could
be called from others, but never used externally to the
class implementation.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are action errors?

722


Describe validate() and reset() methods.

757


What is the purpose of action tag in struts.xml?

720


What are pull and push mvc architecture and which architecture does struts2 follow?

684


Is struts compatible with other java technologies?

689


Explain about struts relation to html tags?

715


What is the difference between session scope and request scope when saving formbean ?

737


What is difference between actionform and dynaactionform?

764


Who wrote struts?

716


What are the loop holes of struts?

758


What are the core components of a struct2 based application?

753


What is the purpose of @emailvalidator?

727


What is difference between spring and struts?

667


What are the 5 constants of action interface?

747


in struts how to use hibernate with struts>

1989