HELP! * GREY=local LOCAL HTML version of Foils prepared July 10 1996

Foil 64 Constructors of Objects

From Basic Lectures on Java Language Applets Graphics Networking Trip to China and Icase Tutorial -- July 12-28 and June 10-13 96. by Geoffrey C. Fox * Important Information in IMAGE

Methods of identical name to class are special -- they are constructors
mPoint() { /* Default Constructor */
  • x=0;
  • y=0;
}
We can overload method to define different versions with different numbers and types of arguments
mPoint(int x, int y) { /* Constructor to set Specific Initial values */
  • this.x = x;
  • this.y = y;
}
Note this refers to current object
mPoint can have other methods to set its instance variables such as:
public void setDelta(int _dx, int _dy) {
  • dx = _dx;
  • dy = _dy;
} /* where we don't need this as used _dx, _dy */



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Feb 18 1997