Basic HTML version of Foils prepared May 12 1996

Foil 55 Constructors of Objects

From CRPC Lectures on Java Language Applets Graphics CRPC Annual Meeting Tutorial -- May 14,1996. by Geoffrey C. Fox


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

in Table To:


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 Dec 14 1997