I keep getting StackOverFlowException whenever I instantiate an instance of A class. I know it has got something to do with the fact that A.b field is of type derived from class A. But why would that cause an exception?
static void Main(string[] args)
{
A a = new A(); // exception
}
class A
{
private B b = new B();
}
class B:A {}
thank you
Here is what is happening under the hood
Bfor the private fieldbBderives fromAand hence has it’s own fieldb. At this point it goes back to step #2 and repeats until a stack overflow occurs