构造函数,可以是私有的,我不明白,私有的用的何处呢?
------------------------------------------------------
类是通过构造函数实例化的,这就要求构造函数必须是公有的,才有意义呀,因为实例化时,必须从类外调用构造函数呀。
但是如果构造函数是私有的话,就无法实例化呀。

解决方案 »

  1.   

    可以不让你构造 
    比如你 A a=new A()
    私有的就不行
      

  2.   

    class A
    {
        private A(){}
        public A getA(
            return new A();
        )
    }
      

  3.   

    不允许你外部构造,但可以在内部通过公共构造函数调用

    private class1(){...}
    public class1(arg list):this(){...}
      

  4.   

    这样做的 好处是  封闭别的类中 直接new 这个类,然后可以在这个类中自定义一个new 实例的方法。
    像 Graphics pea=Form.CreateGraphics();
      

  5.   

    不允许你外部构造,但可以在内部通过公共构造函数调用 
    例如单例模式经常这么做 
    class test
    {
    private static test t =null;
    private test()
    {
    }public static test GetTest()
    {
    if(t == null)
    {
    t = new test();
    }
    return t;
    }
    }
      

  6.   

    你老婆是你的私有方法  只有你这个类才能调的动她和你正大光明的KISS  其他的不得行