Stop show with sound -- Keyboard shortcut: 'x'  Next slide in show -- Keyboard shortcut: 'n'  3 minutes, 14 secondsObjekt-orienteret programmering i Java, del 1 - slide 17 : 27

Konstruktorer i klassen Point 

class Point{

  private double x, y;

  public Point(){
    this(0.0, 0.0);  
  }

  public Point(double x){
    this.x =  x; this.y = 0.0;
  }

  public Point(double x, double y){
    this.x = x;
    this.y = y;
  }

  public Point(Point p){
    this(p.x, p.y);
  }

  // Evt. Point methoder her

  public String toString(){
    return ("Punktet" + "(" + x + "," + y + ")");
  }
} // end class Point
 

ConstructorDemo.javaEn anvendelse af de fire konstruktorer vist ovenfor.