PPT Slide
Defining Constructors
Class Body {
public long idNum;
public String name = "unnamed";
public Body orbits = null;
private static long nextID = 0;
Body( ) {
idNum = nextID++;
}
Body(String bodyName,
Body orbitsAround) {
this();
name = bodyName;
orbits = orbitsAround;
}
}
NOTE: a constructor can invoke another
constructor from the same class using this.
*
Previous slide
Next slide
Back to first slide
View graphic version