title: How to access private variables in a Java class method
body: <p>I am trying to access a private variable (<code>x</code>) in my method <code>distanceFromPoint</code> but it seems it doesn't work. How can I access it? My method is returning <code>0.0</code> all the time regardless of other values.</p>
  
  <h3>Code</h3>
  
  <pre><code>public class Pointdeclare {
      private static int x;
      private static int y;
  
      Pointdeclare (int x_ , int y_ ){
          this.x = x_;
          this.y = y_;
      }
  
      int getX(){
          return x;
      }
  
      int getY(){
          return y;
      }
  
      static double distanceFromZero (){
          return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
      }
  
      double distanceFromPoint(Pointdeclare point){
          int distX = point.getX()- this.x;
          int distY = point.getY()- this.y;
  
          return (double) Math.sqrt(Math.pow(distX, 2) + Math.pow(distY, 2));
      }
  }
  </code></pre>
  
  <h3>Main Class</h3>
  
  <pre><code>public class main {
      static Pointdeclare p1 = new Pointdeclare(6, 7);
      static Pointdeclare p2 = new Pointdeclare(3, 7);
  
      public static void main (String[] args){
          System.out.println(p2.distanceFromZero());
  
          System.out.print(p1.distanceFromPoint(p2));
      }
  }
  </code></pre>