Yes, you can use the singleton pattern, described e.g. by Gamma et al.
Example:
public class SingletonClass {
private static SingletonClass mInstance;
private SingletonClass() {
...
}
public SingletonClass getInstance() {
if (mInstance == null) {
mInstance = new SingletonClass();
}
return mInstance;
}
}
Other classes can only get an instance (nay, *the* instance!) of the class
by calling the getInstance() method.
Hope this helps,
Manne
-----Original Message-----
From: Sanjay Vashisht [mailto:[EMAIL PROTECTED]]
Sent: 10 October 2000 06:42
To: [EMAIL PROTECTED]
Subject: offtopic: Can i have only one object for a class
Hi All
This is an off-topic but an interesting question?
can i have only one object for a class defined. If user try to create
one more object that should be an Exception or error condition.
Thanks in Advance.
Rgds
Sanjay
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets