Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Constructors in a class
Ravi Hyd
Greenhorn
Posts: 4
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 229
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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:
public class Singleton { private Singleton() {} private static Singleton instance; public static Singleton getInstance() { if(instance == null) { instance = new Singleton(); } return instance; } }
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Doubt
Java Network Question, pls help
connection pooling in struts
How to get current date in October 10, 2005. 9.30 a.m format
Can a class be private?
More...