| Author |
Private Constructors in j2se
|
Pandu Rangam
Greenhorn
Joined: Dec 08, 2006
Posts: 24
|
|
|
Can any one tell is there any class with a private constructor in j2se api other than Math class?
|
SCJP 1.4,<br />SCWCD 1.4
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
Sure, lots. java.lang.System and java.util.Arrays are the first two that come to mind.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Pandu Rangam
Greenhorn
Joined: Dec 08, 2006
Posts: 24
|
|
|
if the constructor is private, then is it a singleton. I mean Math,Runtime, System etc are following Singleton design pattern?
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Originally posted by Pandu Rangam: if the constructor is private, then is it a singleton. I mean Math,Runtime, System etc are following Singleton design pattern?
No. Singleton implies private constructor, but private constructor does not imply Singleton. A private constructor may be used to help to forbid any instantiation of a utility class. It may also be used for instantiable classes whose public construction interface is a factory method, rather than a constructor. Type-safe enums, pre Java 5, are another use. There are probably more.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
 |
|
|
subject: Private Constructors in j2se
|
|
|