构造函数,可以是私有的,我不明白,私有的用的何处呢?
------------------------------------------------------
类是通过构造函数实例化的,这就要求构造函数必须是公有的,才有意义呀,因为实例化时,必须从类外调用构造函数呀。
但是如果构造函数是私有的话,就无法实例化呀。
------------------------------------------------------
类是通过构造函数实例化的,这就要求构造函数必须是公有的,才有意义呀,因为实例化时,必须从类外调用构造函数呀。
但是如果构造函数是私有的话,就无法实例化呀。
比如你 A a=new A()
私有的就不行
{
private A(){}
public A getA(
return new A();
)
}
如
private class1(){...}
public class1(arg list):this(){...}
像 Graphics pea=Form.CreateGraphics();
例如单例模式经常这么做
class test
{
private static test t =null;
private test()
{
}public static test GetTest()
{
if(t == null)
{
t = new test();
}
return t;
}
}