2010-03-30 Jb Evain <jbevain@novell.com>
[mcs.git] / docs / ecma334 / 17.10.5.xml
blob6d4f95a21363ae078e9fe47085b89c5a3b2fbcdd
1 <?xml version="1.0"?>
2 <clause number="17.10.5" title="Private constructors">
3   <paragraph>When a class declares only private instance constructors, it is not possible for other classes to derive from that class or to create instances of that class (an exception being classes nested within that class). <example>[Example: Private instance constructors are commonly used in classes that contain only static members. For example: <code_example><![CDATA[
4 public class Trig  
5 {  
6    private Trig() {}   // Prevent instantiation  
7    public const double PI = 3.14159265358979323846;  
8    public static double Sin(double x) {...}  
9    public static double Cos(double x) {...}  
10    public static double Tan(double x) {...}  
11 }  
12 ]]></code_example></example></paragraph>
13   <paragraph><example>The Trig class groups related methods and constants, but is not intended to be instantiated. Therefore, it declares a single empty private instance constructor. end example]</example> At least one instance constructor must be declared to suppress the automatic generation of a default constructor. </paragraph>
14 </clause>