2
Reply

How to invoke or instantiate obj using private constructor?

Abid Khan

Abid Khan

Jan 20 2015 6:21 AM
746
Hello, i would like to know how to instantiate an object using private constructor? and what are the main benefits to use private constructor?
 
namespace Practice
{
public class Test
{
int a;
public Test()
{
}
private Test(int a)
{
this.a = a;
}
}
public class Test2
{
void method()
{
Test obj1 = new Test();
}
}
}

Answers (2)