Basic HTML version of Foils prepared 18 May 97

Foil 41 Constructors of Objects

From Java Tutorial - Spring 1997 Part II: Java Language and Object-Oriented Concepts Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,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 */
  • x = _x;
  • y = _y;
6 }
7 mPoint can have other methods to set its instance variables such as:
8 public void setDelta(int _dx, int _dy) {
  • dx = _dx;
  • dy = _dy;
9 }

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 Thu Jan 8 1998