title: Understanding how variable point to value in Java
body: <p>I have a below code. The variable <code>c</code> and <code>d</code> are class variables and initially they were pointing to value 0, but when I did  <code>c=a* a;</code> and <code>d =b* b*b</code> they printed value as 25 and 64 which is correct. so what I think now is that the <code>c</code> and <code>d</code> are now pointing to value 25 and 64 and they are class variables, so if I do <code>j=c+d;</code> it should give me 89 as <code>j</code> value, but it is giving me 0... why? I know if I use <code>static</code> with <code>c</code> and <code>d</code> variable it will give me 89 value... but why I should use <code>static</code> as <code>c</code> and <code>d</code> are global variables and there values are now updated to 25 and 64. Please let me know. Thanks.</p>
  
  <pre><code>public class BaiscSum {
  
      int a=5;
      int b=4;
      int c;
      int d;
      int j;
  
      public void square() {
          c=a*a;
          System.out.println(c);   
      }
  
      public void cube() {
          d=b*b*b;
          System.out.println(d);
      }
  
      public void sum() {
          j=c+d;
          System.out.println(j);
      }
  
      public static void main(String[] args) {
          BaiscSum squ= new BaiscSum();
          squ.square();
  
          BaiscSum cub = new BaiscSum();
          cub.cube();
  
          BaiscSum su = new BaiscSum();
          su.sum();    
      }
  }
  </code></pre>