title: How to call non-static method from another class?
body: <p>I have 3 classes: <code>Point</code>, <code>Polygon</code> and <code>ClientePolygon</code>. <code>Point</code> creates an object, <code>Point(double x, double y)</code> with many nonstatic methods. <code>Polygon</code> creates an array of <code>Point</code> with non-static methods, i.e., write, move, and return the <code>Point</code> closest to the origin in the array. <code>ClientePolygon</code> executes <code>Polygon</code>. The problem is that when I run ClientePolygon it gives me <code>Point class executed...</code> and I want to run Polygon. Any suggestions? Thanks a lot.</p>
  
  <p>ClientePolygon:</p>
  
  <pre><code>package k;
  public class ClientePolygon {
      public void main(String [] args){
          Point origem = new Point (0,0);
          Point [] vertices = new Point[4];
          vertices[0] = new Point (1.0,1.0);
          vertices[1] = new Point (1.0,5.0);
          vertices[2] = new Point (2.0,5.0);
          vertices[3] = new Point (2.0,1.0);
  
          for (int i = 0; i &lt; vertices.length; i++) {
  
          vertices[i].translate(5.0,7.5);
  
          }
      }
  }
  </code></pre>
  
  <p>Point:</p>
  
  <pre><code>package k;
  
  public class Point {
  
      private double x;
      private double y;
  
      public Point(double x, double y){
  
          this.x = x;
  
          this.y = y;
  
      }
  
      public double getX(){
  
          return x;
  
      }
  
      public String toString(){
  
          return "("+ this.x+", "+this.y+")";
      }
  
      public Point copy(){
  
          Point copia = new Point(x, y);
  
          return copia;
  
      }
  
  
       public static double distance(Point ponto1, Point ponto2){
  
           double distX = ponto1.x + ponto2.x;
  
           double distY = ponto1.y + ponto2.y;
  
           return Math.sqrt(distX*distX + distY*distY);
  
       }
  
       public void translate(double dx, double dy){
  
           double transX = this.x + dx;
  
           double transY = this.y + dy;
  
           System.out.println(toString()+" fica "+ transX +" e "+ transY);
  
       }
  
       public static void main(String[] args) {
  
           Point ponto1 = new Point(2,1);
  
           Point ponto2 = new Point(3,9);
  
           System.out.println(ponto1.toString());
  
           System.out.println(ponto2.toString());
  
           System.out.println("A distancia entre os pontos eh: " +distance(ponto1, ponto2));
  
           System.out.println("O ponto copiado eh: "+ponto2.copy());
  
           ponto2.copy().translate(2, 3);
  
      }
  
  }
  </code></pre>
  
  <p>Polygon:</p>
  
  <pre><code>package k;
  
  public class Polygon {
  
      private Point [] vertices;
  
      public Polygon(Point [] vertices){
  
          this.vertices = vertices;
  
      }
  
      public String toString(){
  
          return "Ponto 1 em: "+vertices;
  
      }
  
      public Point closestToOrigin(){
  
          Point proximo = new Point(0, 0);
          Point origem = new Point(0,0);
  
          for (int i = 0; i &lt; vertices.length; i++) {
  
              double distancia = Point.distance(vertices[i], origem);
  
              if(distancia&lt;Point.distance(vertices[i-1], origem)){
  
                  proximo = vertices[i];
  
              }
  
          }
  
          return proximo;
  
      }
  
      public void translate(double dx, double dy){
  
          Point Trans = new Point(dx, dy);
  
          System.out.println("Ponto 1 fica: "+vertices[0]+Trans+", Ponto 2 fica: "+vertices[1]+Trans+" e Ponto 3 fica: "+vertices[2]+Trans);
  
      }
  
  }
  </code></pre>