When you instantiate a new object by calling constructor, i.e.
Foo bar = new Foo(var);
When does the code in the constructor actually gets invoked in relations to object creation heap? When the constructors modifies member variables of bar, is storage for the variables already allocated and contain default values?
Once
newis called it knows how much memory needs to be allocated into the heap for a variable of type, in your case Foo. Once that memory is allocated only then are the values set. Think about it how else are you going to assign member variables if you don’t have memory for the member variable? If there is no memory new will throw an exception which you need to handle.Process:
newnull