title: Calculating the distance between 2 Points in 2D and 3D
body: <p>I'm just trying to solve a very simple problem, but I have some minor isses. Hope you can help out a beginner real quick ;)</p>
  
  <p>I have 2 classes 'Point' and 'Point3D' which look like that:</p>
  
  <pre><code>public class Point {
      protected double x;
      protected double y;
  
      Point(double xCoord, double yCoord){
          this.x = xCoord;
          this.y = yCoord;
      }
  
      public double getX(){
          return x;
      }
  
      public double getY(){
          return y;
      }
  
      public static double distance(Point a, Point b)
      {
          double dx = a.x - b.x;
          double dy = a.y - b.y;
          return Math.sqrt(dx * dx + dy * dy);
      }
  
      public static void main(String[] args) {
          Point p1 = new Point(2,2);
          Point p2 = new Point(5,6);
          System.out.println("Distance between them is " + Point.distance(p1, p2));
      }
  }
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>public class Point3D extends Point {
      protected double z;
  
      Point3D(double x, double y, double zCoord){
          super(x, y);
          this.z = zCoord;
      }
  
      public double getZ(){
          return z;
      }
  
      public static double distance(Point p1, Point p2){
          double dx = p1.x - p2.x;
          double dy = p1.y - p2.y;
          double dz = p1.z - p2.z;
          return Math.sqrt(dx * dx + dy * dy + dz *dz);
      }
  
      public static void main(String[] args) {
          Point3D p1 = new Point3D(-4,2,5);
          Point3D p2 = new Point3D(1,3,-2);
          System.out.println("Distance between them is " + Point3D.distance(p1, p2));
      }
  } 
  </code></pre>
  
  <p>My problem now is the following: 
  If I keep my code like this, my Eclipse is saying that 'z cannot resolved into a field' and as a possible solution I should create it in my class 'Point'.
  After doing that the class 'Point3D' compiles but doesn't calculate the right answer..</p>
  
  <p>Greetings,</p>