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

Foil 63 Instantiating an Object from its Class

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

Suppose we have defined a class called mPoint for a movable point which has position (x,y) Color color and can be moved by amount (dx,dy) at each step
mPoint BunchofPoints[2]; /* defines BunchofPoints to be 2 dimensional array of mPoint objects -- it does not instantiate BunchofPoints */
FirstPoint = new mPoint(); /* Allocates an instance of mPoint and invokes Constructor of mPoint to Initialize */
FirstPoint.dx=5;
FirstPoint.dy=5; /* Redefines values of instance variables dx,dy for object FirstPoint */
mPoint could be defined by
import java.awt.*;
public class mPoint {
  • int x, y;
  • int dx = 1, dy = 1;
  • Color color = Color.black;
}



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