Hi I am working with code that looks something like this .
class A
{
Custom objA;
public A()
{
//Assign some value to objA;
B obj =
Firstly, on line 5, you have a syntax error. You could do B obj = new B(objA)
if you are trying to create a new instance of B
. But I can only guess.
What it seems like you are trying to do is modify objA
by having passed it into a new object of type B
, storing it in a field, and then modifying the field. The problem is that what you are storing is a copy of a reference to objA
. When you do this.objB = null
, you are modifying the field objB
to have a new reference (null
), but you have not done anything to the field objA
which is a member of the instance of class A
.