title: How to pass an object between multiple classes? Java
body: <pre><code>public class FooClass {
      BarClass bar = null;
      int a = 0;
      int b = 1;
      int c = 2;
  
      public FooClass(BarClass bar) {
          this.bar = bar;
          bar.setFoo(this);
      }
  }
  
  public class BarClass {
      FooClass foo = null;
  
      public BarClass(){}
  
      public void setFoo(FooClass foo) {
          this.foo = foo;
      }
  }
  </code></pre>
  
  <p>elsewhere...</p>
  
  <pre><code>BarClass theBar = new BarClass();
  FooClass theFoo = new FooClass(theBar);
  theFoo.a //should be 0
  theBar.foo.a = 234; //I change the variable through theBar. Imagine all the variables are private and there are getters/setters.
  
  theFoo.a //should be 234  &lt;-----
  </code></pre>
  
  <p>How can I pass an object to another class, make a change, and have that change appear in the original instance of the first object? </p>
  
  <p>or</p>
  
  <p>How can I make a cycle where one change to a class is reflected in the other class?</p>