0

Let's say I have two classes. Class1 and Class2.

The constructor of Class2 looks like this:

public Class2{

Class1 c;

    public Class2(Class1 c){
        this.c = c;
    }

}

When creating an instance of Class2 inside the code of Class1, we pass the existing instance of Class1 to Class2. This is from Class1:

Class2 c2 = new Class2(this);

Inside Class2, I want to manipulate the variables inside the instance of Class1 that's been passed to Class2.

My question is:

If I make changes to the c (the instance of Class1 that's been passed to Class2), am I affecting the original instance of Class1, or just a copy?

AvivC
  • 133
  • 2
  • 8

0 Answers0