简单的物理可以解释为传递参数,但是在内存的解释是什么?使得两个对象构成一种联系和引用或者说链接么?

解决方案 »

  1.   

    这个是参数传递,也分配一块内存,java 内存分为三块,这块内存放在那里我忘了,反正这块内存是临时的,建议看马士兵的java基础内存分析。。我上次看了,忘得差不多了。。
      

  2.   

    补充:我知道new是内存分配。但是在另外一个类的构造方法中分配的目的是什么呢?
      

  3.   

    比如说一个程序是功能做馒头,其中有三个类,一个是馒头,一个是馒头筐,一个是厨师馒头的类:
    class WoTou{
       int id;
       WoTou(int id){
          this.id = id;
          }
    }   
    馒头筐的类
    class SyncStack{
       int index = 0;
       WoTou arrWT = new WoTou[6];
       
       void synchronized push(WoTou wt){
          if(index == arrWT.length)
          try(
          this.wait();
          ) catch (InterruptedException e){
             e.printStackTrace();
                }
          index++;
          WoTou[index] = wt;
          }
       
       void synchronized WoTou pop(){
          if(index == 0)
          try(
          this.wait();
          ) catch (InterruptedException e){
             e.printStackTrace();
                }
          index--;
          return WoTou[index];
          }   
       }
    厨师的类:   
    class Producer implements Runnable{
       SyncStack ss = null;
       Producer(SyncStack ss){

          SyncStack ss = ss
          }
       public void run(){
          for(int i = 0 ;i < 20;i++){
             WoTou wt = new WoTou[i];
             ss.push(wt);
                }
          System.out.println("生产了: " + i);
          }   
       
       }
    以上描红的地方,构造方法里面都带有引用,这些引用的作用是什么?