2015-04-20 15:36:01 -07:00
|
|
|
|
//: operators/PassObject.java
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-29 13:56:17 -07:00
|
|
|
|
// Passing objects to methods might not be
|
2015-04-20 15:36:01 -07:00
|
|
|
|
// what you're used to.
|
|
|
|
|
import static net.mindview.util.Print.*;
|
|
|
|
|
|
|
|
|
|
class Letter {
|
|
|
|
|
char c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PassObject {
|
|
|
|
|
static void f(Letter y) {
|
|
|
|
|
y.c = 'z';
|
|
|
|
|
}
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
Letter x = new Letter();
|
|
|
|
|
x.c = 'a';
|
|
|
|
|
print("1: x.c: " + x.c);
|
|
|
|
|
f(x);
|
|
|
|
|
print("2: x.c: " + x.c);
|
|
|
|
|
}
|
|
|
|
|
} /* Output:
|
|
|
|
|
1: x.c: a
|
|
|
|
|
2: x.c: z
|
2015-05-05 11:20:13 -07:00
|
|
|
|
*///:~
|