This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / dummy question about private constructor
-ely(Ely);
2000-11-26
{554}
(#15824@0)
-
Private constructor is useful on some occasion.
-sailor(Sailor);
2000-11-26
{1101}
(#15825@0)
-
Thanks sailor, your explaination is very clear..one more question, does it mean a STATIC PUBLIC method has to be created if we declare a private constructor?
-ely(Ely);
2000-11-26
{109}
(#15829@0)
-
Yes, I think so. If not, it seems no way to create such an object ... (also another public constructor can do the job.)
-sailor(Sailor);
2000-11-26
(#15830@0)
-
Private constructor is related to some design patterns such as the Singleton PatternTake java.lang.Runtime as an example. There is only ONE Runtime for a JVM. Everybody can get that one as follows:
Runtime rt = System.getRuntime();
But nobody is allowed to create a Runtime.
---The constructor of Runtime is private, and correspondingly, Runtime is infertile.
-jabber(jabber);
2000-11-26
{287}
(#15850@0)