Skip to content

Instantly share code, notes, and snippets.

@SanjeevMohindra
Created February 28, 2016 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SanjeevMohindra/63341c3c5ac02e9423dc to your computer and use it in GitHub Desktop.
Save SanjeevMohindra/63341c3c5ac02e9423dc to your computer and use it in GitHub Desktop.
package callbyvalue;
public class ObjectCallWithCreate {
public static void main(String[] args) {
TempNum z = new TempNum(10);
System.out.println("Value of x before the call: " + z);
add(z);
System.out.println("Value of x after the call: " + z);
}
public static void add(TempNum z) {
z = new TempNum(15);
}
}
class TempNum {
public int x;
public TempNum(int x) {
this.x = x;
}
@Override
public String toString() {
return "TempNum [x=" + x + "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment