wood burning stoves 2.0*
The moose likes Java in General and the fly likes Constructors in a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Constructors in a class" Watch "Constructors in a class" New topic

Constructors in a class

Ravi Hyd

Joined: Jun 27, 2005
Posts: 4
I want to know whether we can create a Private default constructor in a class. Can anybody explain what is Singleton class?
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
Yes, it is possible to create a private default Constructor.

If all constructors are private you cannot create an instance from outside that class.

If you create a public static method that always returns the same instance of that class you have used the singleton pattern.

Look at the example:

wood burning stoves
subject: Constructors in a class
Similar Threads
Java Network Question, pls help
How to get current date in October 10, 2005. 9.30 a.m format
connection pooling in struts