Abid Khan

Abid Khan

  • NA
  • 245
  • 25.5k

How to invoke or instantiate obj using private constructor?

Jan 20 2015 6:21 AM
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)