When a class declares only private constructors it is not possible for other classes to derive from the class or create instances of the class (an exception being classes nested within the class). Private constructors are commonly used in classes that contain only static members. For example:
public class Trig { private Trig() {} // Prevent instantiation public const double PI = 3.14159265358979323846; public static double Sin(double x) {...} public static double Cos(double x) {...} public static double Tan(double x) {...} }
The Trig
class provides a grouping of related methods and constants, but is not intended to be instantiated. It therefore declares a single private constructor. Note that at least one private constructor must be declared to suppress the automatic generation of a default constructor (which always has public access).