Quick question, I tried to find a satisfactory answer on my own.
Say I have 2 classes Object1 and Object2. Now I want Object2 to do use Object1’s resources so I do this
Object1 obj1;
public Object2(Object1 o){
obj1 = o;
}
and in Object1 I do this
new Object2(this);
Does this give each Object2 an Object1, or does it simply point to the Object1 as expected?
It will point to
Object1as expected. This is because Java stores object variables as “references”(“pointers” if you like thinking in C) and, when you pass this reference by value, you are giving the function the objects reference.. There is a good basic tutorial on this functionality here. Hope this helps.