title: Static class variables are created when Static methods are being called - Java
body: <p>I have a controller class that has both static and non-static variables and methods. </p>
  
  <pre><code>public class Controller 
  {
      // Model that will be used throughout the program
      private static Model model;
      private static ArrayList&lt;Model&gt; modelList = new ArrayList&lt;Model&gt;();
  
      // User Views
      private static OpenProgramView initialView = new OpenProgramView();
      private DriverProfileView driverProfileView;
  }
  </code></pre>
  
  <p>There is also a static method that I need so that other classes can access it without a controller instance. The following is the call upon this method:</p>
  
  <pre><code>int askYear = Controller.getModel().getYear();
  </code></pre>
  
  <p>The issue I am having, is that when I use the previous line of code, it seems to call a new instance of the private static object - OpenProgramView. I know this because it pops up during testing when it shouldn't. I also changed other views from non-static to static to see what would happen and they also pop up when I use the static method, but the non-static views were not popping up. </p>
  
  <p>My question - why is this happening? It seems that when I call a static method it is creating a new instance of all of the static class variables in controller and is creating an issue.</p>
  
  <p>Edit:</p>
  
  <p>I didn't specify that this only happens when I am testing this specific snippet of code. When this problem occurred I had not yet created a Controller object, thus the first time I touch the Controller class is with the call to the static method.</p>
  
  <p>When I run the program out of test mode and actually use it for functional purposes - a Controller object has already been created at the creation of the program, thus, this issue doesn't occur once I call the static method, because it isn't the first time I've "touched" the class. Thanks for the help.</p>