Array assignment and reference in Java

前端 未结 5 1469
误落风尘
误落风尘 2020-12-11 08:24
public class Test {
    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 5};
        int[] b = a;
        int[] c = {6, 7, 8};
        a = c;
         


        
5条回答
  •  [愿得一人]
    2020-12-11 08:46

    This is why:

    What is Object Reference Variable?

    You have 2 objects (the arrays) and 3 references (a, b, c) to the objects. You're just swapping around where things are pointed.

提交回复
热议问题