Skip to content

Instantly share code, notes, and snippets.

@vittee
Forked from anonymous/pass-by-ref-2.cs
Last active December 10, 2015 22:38
Show Gist options
  • Save vittee/4504167 to your computer and use it in GitHub Desktop.
Save vittee/4504167 to your computer and use it in GitHub Desktop.
public class Test {
public static void main(String[] args) {
A a = new A(5);
System.out.println(a.a);
test(a);
System.out.println(a.a);
}
public static void test(A a) {
a.a = 3 ;
}
}
class A {
private int _a;
public A(int value) {
this.a = value;
}
public double a
{
get { return _a; }
set { _a = value; }
}
}
public class Test {
public static void main(String[] args) {
A a = new A(5);
System.out.println(a.getValue());
test(a);
System.out.println(a.getValue());
}
public static void test(A a) {
a.setA(3);
}
}
class A {
private int value;
public A(int initialValue) {
this.value = initialValue;
}
public void setA(int newValue) {
this.value = newValue;
}
public int getValue() {
return this.value;
}
}
public class Test {
public static void main(String[] args) {
int a = 5;
System.out.println(a);
test(a);
System.out.println(a);
}
public static void test(int a) {
a = 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment