title: Sharing class attributes in Java
body: <p>Let's consider this example :</p>
  
  <pre><code>public class Shared {
  
      private int attribute;
  
      public Shared() {}
  
      public void incrementAttribute(int i) {
              attribute += i;
      }
  
      public int getAttribute() {
              return attribute;
      }
  
      public static void main(String[] args) {
              Shared s1 = new Shared();
              Shared s2 = new Shared();
  
              s1.incrementAttribute(1);
              s2.incrementAttribute(1);
  
              s1.getAttribute();
              s2.getAttribute();
      }    
  }
  </code></pre>
  
  <p>How can I change this class to have <code>1</code> <code>2</code> in output when calling <code>getAttribute()</code> and not <code>1</code> <code>1</code></p>
  
  <p>Something like a global variable, I tried the <code>final</code> keyword but I can't set something using a Method.</p>