Skip to content

Instantly share code, notes, and snippets.

@SanjeevMohindra
Created February 28, 2016 14:25
Show Gist options
  • Save SanjeevMohindra/06e382c1670e23fa5dea to your computer and use it in GitHub Desktop.
Save SanjeevMohindra/06e382c1670e23fa5dea to your computer and use it in GitHub Desktop.
package callbyvalue;
public class ObjectCall {
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.x = 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