I have something like this:
public class Test {
public static MyObject o4All = null;
public MyObject o4This = null;
public void initialize() {
// create an instance of MyObject by constructor
this.o4This = new MyObject(/* ... */);
// this works, but I am wondering
// how o4All is internally created (call by value/reference?)
Test.o4All = this.o4This;
}
}
I know, I should assign or change a static variable only by a static method. But according to java-docs (http://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html), I can use an object reference.
Class methods cannot access instance variables or instance methods directly—they must use an object reference.
What if I change a property of o4This? Will the property of o4All also be changed indirectly?