public static void main(String[] args) { Integer a = 1; Integer b = 0; b=a; System.out.println(a); System.out.println(b); ++a; System.out.println(a); System.out.println(b); }
output: 1 1 2 1
public static void main(String[] args) { ArrayList<Integer> a = new ArrayList<Integer>(); ArrayList<Integer> b = new ArrayList<Integer>(); a.add(1); a.add(1); a.add(1); a.add(1); b=a; System.out.println(a.size()); System.out.println(b.size()); b.add(2); System.out.println(a.size()); System.out.println(b.size()); }
output: 4 4 5 5
For the code above, why both objects do not belong to the same memory location.
source share