title: Java- incrementing a counter which is a class variable
body: <p>I have a question where part of it says:</p>
  
  <p><em>The class Vehicle has 4 attributes namely noOfTyres, accessories, brand and counter which are of type integer, Boolean, String and integer respectively. Counter is a class variable. The constructor of the class initialises all 3 variables and increments the counter by one.</em> </p>
  
  <p>I have thought of two approaches for this part and I am not sure which one is correct or if both of them is.</p>
  
  <p>The first one is:</p>
  
  <pre><code>public class Vehicle{
    private int noOfTyres;
    private Boolean accesories;
    private String brand;
    private int static counter=0;
    private int counterNum;
  
  public Vehicle(int noOfTyres, int accessories, int brand){
   counter++;
   this.noOfTyres= noOfTyres;
   this.accessories= accessories;
   this.brand= brand;
   counterNum= counter;}
  
  }
  </code></pre>
  
  <p>The second one is:</p>
  
  <pre><code>  public class Vehicle{
     private int noOfTyres;
     private Boolean accesories;
     private String brand;
     private int counter=0;
  
  
  public Vehicle(int noOfTyres, int accessories, int brand){
   counter++;
   this.counter= counter;
   this.noOfTyres= noOfTyres;
   this.accessories= accessories;
   this.brand= brand;
   }
  
  }
  </code></pre>
  
  <p>Which approach(if any of them is good) is suitable based on the type/amount of info the question gave?</p>