// Helene Martin, CSE 142 // In Java, primitive types use value semantics so assignment results // in copying a value. Object types use reference semantics so assignment // results in copying a REFERENCE (memory location) to an object. // Below, the variables array1 and array2 hold the same memory location: // they refer to the same array. import java.util.*; public class ReferenceValueSemantics { public static void main(String[] args) { int a = 12; int b = a; b = 5; // only changes b System.out.println(a + " " + b); int[] array1 = {1, 2, 3, 4}; int[] array2 = array1; array2[0] = 555; // changes array2[0] AND array1[0] System.out.println(Arrays.toString(array1)); System.out.println(Arrays.toString(array2)); } }