title: java vs C++ pass by reference
body: <p><br>
  I am confused in the following:<br>
  In C++ we can pass a parameter to a function by reference (having declared it as a pointer or reference variable) and if we modify it inside the function, the changes are reflected to the caller when the function returns.<br>
  This is not happening in java and I am not sure I understand why.</p>
  
  <p>E.g. this is a method from an object X</p>
  
  <pre><code>public boolean aMethod(int id, myClass aClass)
  {
     //do some logic
     aClass = new MyClass();
     //configure argument object aClass
     return true;
  }
  </code></pre>
  
  <p>In the <strong>calling code</strong>:  </p>
  
  <pre><code>//some code processing
  myClass obj = null;
  if(X.aMethod(2,obj))
  {
    obj.methodA();//start using the object
  }
  </code></pre>
  
  <p>I use it in C++, i.e. to return a result that notifies that the function parameter can be used, but in java this does not work.<br>
  I enter the if(X.aMethod(2,obj)) branch but the obj is null. Why is it null?<br>
   Haven't I assigned a memory address from the heap using new inside the method aMethod(int id, myClass aClass)? Am I not passing the "address" of obj in the function?
  I was expecting to have the obj properly constructed and usable in the calling code. Have I misunderstood something concerning memory in java?</p>