The reference mystery problem on the next slide depends on the following definition of a BasicPoint
class:
public class BasicPoint { int x; int y; public BasicPoint(int initialX, int initialY) { x = initialX; y = initialY; } }
The following program produces 5 lines of output. Write each line of output as it would appear on the console.
public class ReferenceMystery { public static void main(String[] args) { BasicPoint p = new BasicPoint(11, 22); int[] a = {33, 44}; int n = 55; System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); // 11,22 [33, 44] 55[^0-9,]+ mystery(p, a, n); // 44,22 [44, 77] 0[^0-9,]+ System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); // 44,22 [44, 77] 55[^0-9,]+ a[0] = a[1]; p.x = p.y; mystery(p, a, n); // 55,22 [88, 77] 0[^0-9,]+ System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); // 55,22 [88, 77] 55[^0-9,]+ } public static int mystery(BasicPoint p, int[] a, int n) { n = 0; a[0] = a[0] + 11; a[1] = 77; p.x = p.x + 33; System.out.println(p.x + "," + p.y + " " + Arrays.toString(a) + " " + n); return n; } }