title: Creating a getCounter() method to count up when the method is called
body: <p>I am trying to create a <code>getCounter()</code> method which will count upwards each time the <code>getCounter()</code> method is called. For example if the method is called 10 times then the output should be: 1,2,3...10.</p>
  
  <p>This is the current code I have:
  Main class:</p>
  
  <pre><code>public class JavaLab5 {
      public static final int DEBUG = 0;
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
  
          Student s[] = new Student[10];
  
  
          s[0] = new MathStudent("Smith");
          s[1] = new MathStudent("Jack");
          s[2] = new MathStudent("Victor");
          s[3] = new MathStudent("Mike");
          s[4] = new ScienceStudent("Dave");
          s[5] = new ScienceStudent("Oscar");
          s[6] = new ScienceStudent("Peter");
          s[7] = new ComputerStudent("Philip");
          s[8] = new ComputerStudent("Shaun");
          s[9] = new ComputerStudent("Scott");
  
          for (int loop = 0; loop &lt; 10; loop++) {
              System.out.print(loop);
              System.out.println(s[loop].getSubjects());
          }
  
      }
  
  }
  </code></pre>
  
  <p>Student class:</p>
  
  <pre><code>public class Student {
      String name;
      int count 
      public static int instances = 0;
  
      //Getters
      public  String getName() {
          return this.name;
      }
  
      // Setters
      public void setName(String name) {
          if (JavaLab5.DEBUG &gt; 3) System.out.println("In Student.setName. Name = "+ name);
          this.name = name;
      }
  
      /**
       * Default constructor. Populates name,age and gender 
       * with defaults
       */
      public Student() {
          instances++;
          this.name = "Not Set";
      }
  
      /** 
       * Constructor with parameters 
       * @param name String with the name
      */
      public Student(String name) {
          this.name = name;
      }
  
      /**
       * Destructor
       * @throws Throwable 
       */
      protected void finalize() throws Throwable {
          //do finalization here
          instances--;
          super.finalize(); //not necessary if extending Object.
      } 
  
      public void getCounter() {
          for (int x = 0; x &lt; 10; x++) {
          count++;
          System.out.println(count);
      }
      }
      public String toString () {
          return this.name; 
      }
  
      public String getSubjects() {
        return this.getSubjects();
      }
  }
  </code></pre>
  
  <p>My question is how I can implement such a method to call it from my Main class.</p>