title: What is the proper way of accessing static fields in Java?
body: <p>I just started learning Java and I wrote a class to test using static fields. Everything works fine but in Eclipse I see an icon which when hovered comes out as: "The static method getCounter from the type CarCounter should be <strong>accessed in a static way</strong>." What's the right way then?</p>
  
  <p>Here's the class:</p>
  
  <pre><code>public class CarCounter {
      static int counter = 0;
  
      public CarCounter(){
          counter++;
      }
  
      public static int getCounter(){
          return counter;
      }
  }
  </code></pre>
  
  <p>And here's where I try to access variable counter:</p>
  
  <pre><code>public class CarCounterTest {
      public static void main( String args[] ){
          CarCounter a = new CarCounter();
          System.out.println(a.getCounter()); //This is where the icon is marked
      }
  }
  </code></pre>