dcsimg
can we define constructor with private access specifier
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, April 21, 2005 08:05 AM

can we define constructor with private access specifier

Re: can we define constructor with private access specifier

Posted By:   Anonymous  
Posted On:   Friday, April 22, 2005 02:39 AM

Yes. For example, you can create Singletons using private constructor.

public class SingletonObject {

private SingletonObject() {
// no code req'd
}

public static SingletonObject getSingletonObject() {
if (ref == null) {
// it's ok, we can call this constructor
ref = new SingletonObject();
}
return ref;
}

private static SingletonObject ref;
}
About | Sitemap | Contact