using System;
class ClassOfInts
{
public int x;
public int y;
}
class Test
{
ClassOfInts objClassOfInts;
string name;
public TestMethod(int p, int q, string s)
{
objClassOfInts=new ClassofInts;
objClassOfInts.x=p;
objClassOfInts.y=q;
name=s;
}
}
class Main
{
static Main()
{
Test t1=new Test();
Test t2=new Test();
t1.TestMethod(1,2,"First");
//XXX
t2.TestMethod(2,3,"Second");
//YYY
}
}
What is the memory allocation of above program when it reaches XXX. Will reference variable objClassInts still be reffering to its object in Heap. or As soon as TestMethod finishes Execution, objClassInts will be reffering to null.
objClassOfInts will not be null. It starts as null, but as long as a Test object is live, all it’s referenced objects will also be live.