title: Why is my variable being set equal to an incorrect value despite explicitly being set equal to the correct one in three different locations?
body: <p>We have to write a program to simulate a bank for my Computer Science class. The program has three tellers, where customers can go. The third teller takes a stack of tasks when it's size is larger than 0. I instantiated the data values for this third teller in the data field as follows: </p>
  
  <pre><code>public static Task firstTask = new Task(916,3); 
  
  public static  Teller teller3 = new Teller(new Customer(0,0,0),firstTask,3); 
  </code></pre>
  
  <p>I then have a method that I wrote to make the teller start task in the teller class. </p>
  
  <pre><code>public  void startTask(Task arrivingTask) { 
  
      currentTask = arrivingTask; 
  
  }
  </code></pre>
  
  <p>I call this with the same value of firstTask in the main method.  </p>
  
  <pre><code>teller3.startTask(firstTask); 
  </code></pre>
  
  <p>After this, I push onto the taskStack 2 new tasks. </p>
  
  <pre><code>    taskStack.push(new Task(910,12)); 
      taskStack.push(new Task(913,3)); 
  </code></pre>
  
  <p>I also instantiate the nextTask (the next task to arrive on the arrivals file). </p>
  
  <pre><code>Task nextTask = new Task(925,2); 
  </code></pre>
  
  <p>I also have a print method in the teller class to print the task. </p>
  
  <pre><code>public void printTask() { 
  
      System.out.println("currentTask = (" + this.currentTask.getArrival() + "," + this.currentTask.getServiceTime() + ")");  
  
  }
  </code></pre>
  
  <p>If I run this code: <code>teller3.printTask();</code> , the output is currentTask = (925,2).</p>
  
  <p>I do not experiance this issue when doing something similar with customers. I am instantiating these values in the data field, and doing things such as taskStack.push(n), where n = new Task(910,12). Everything else in my code works perfectly, except for this. </p>
  
  <p>Later on in the code, event5, the event which handles task completion, contains the following code pertaining to the task, and nothing else. </p>
  
  <pre><code>firstTask.printTask(); 
  
      if (taskStack.getSize() &gt; 0) { 
          System.out.println(currentTime); 
  
          firstTask = taskStack.pop(); 
          teller3.startTask(firstTask);
          Event newEvent = new Event(currentTime + 
  teller3.T1ServiceTime(),5); 
  
          Elist.insert(newEvent); 
          teller3.isBusy = true;
          firstTask.printTask(); 
      }
  </code></pre>
  
  <p>Here, you can see that I did two things. I first printed the task. The task always prints as the value I assigned earlier to nextTask, which I never in my program declare as firstTask. When the taskStack is larger than 0, I set the firstTask equal to taskStack.pop(). It actually does pop the value, but it doesn't change the value of firstTask. I know from the event list because a new event is added every for three minutes later. I print the task again after the if statement runs (which I know from the code it does run), and the firstTask does not change its value. Where should I go from here? </p>