HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 1 February 97

Foil 8 Constructors of Objects

From Jan 27 Delivered Lecture for Course CPS616 -- Java Lecture 2 -- Basic Applets and Objects CPS616 spring 1997 -- Jan 27 1997. by Nancy McCracken * See also color IMAGE
Secs 67.6
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 */
  • x = _x;
  • y = _y;
}
mPoint can have other methods to set its instance variables such as:
public void setDelta(int _dx, int _dy) {
  • dx = _dx;
  • dy = _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 Sun Feb 16 1997