title: Custom toString() in java
body: <p>I'm studying to do my java OCA test, using the book "Java SE7 Programming Essentials" by Michael Ernest. This is my code for one of the answers to a question below:</p>
  
  <pre><code>public class Point3D {
      int x, y, z;
  
      public void setX(int x) {
          this.x = x;
      }
  
      public int getX() {
          return this.x;
      }
  
      public void setY(int y) {
          this.y = y;
      }
  
      public int getY() {
          return this.y;
      }
  
      public void setZ(int z) {
          this.z = z;
      }
  
      public int getZ() {
          return this.z;
      }
  
      public String toString(Point3D p) {
          String result = p.getX() + "," + p.getY() + "," + p.getZ();
          return result;
      }
  
      public static void main(String args[]) {
          Point3D point = new Point3D();
          point.setX(5);
          point.setY(12);
          point.setZ(13);
          System.out.println(point.toString(point));
      }
  }
  </code></pre>
  
  <p>My code works, but in the last line, I think I've made my code in a weird way, shouldn't there be a way to make just <code>point.toString()</code> and not <code>point.toString(point)</code> return the String representation of the point? Can anyone explain to me how to fix it?</p>
  
  <p>I'm sure it's a simple answer, just trying to understand it because I suspect it points to a hole in my java knowledge.</p>