• Post Reply Bookmark Topic Watch Topic
  • New Topic

Private Constructors in j2se  RSS feed

 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell is there any class with a private constructor in j2se api other than Math class?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, lots. java.lang.System and java.util.Arrays are the first two that come to mind.
 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!