// "pass by reference" DIS // modified by Kiri Wagstaff, wkiri@cs.cornell.edu // How do you "pass an object"? technically, by value, but what you're // really passing is the reference value, which is the address of the // object. A call to the method stores the address of the object in // the formal parameter of the method. class Data1 { int k = 0; } public class Pass1 { public static void change(Data1 x) { System.out.println("Before changing: " + x.k); x.k++; System.out.println("After changing: " + x.k); } public static void main(String[] args) { Data1 d = new Data1(); d.k = 1; System.out.println("Before passing: " + d.k); change(d); System.out.println("After passing: " + d.k); } }