Play audio slide show -- Keyboard shortcut: 'x'  Lecture overview -- Keyboard shortcut: 'u'  Previous page: Konstruktor i klassen <kbd>Konto</kbd> -- Keyboard shortcut: 'p'  Next page: Værdier i forhold til objekter -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home  Play sound for this slide -- Keyboard shortcut: 'y'    Objekt-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.