1 |
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
|
2 |
mPoint BunchofPoints[2]; /* defines BunchofPoints to be 2 dimensional array of mPoint objects -- it does not instantiate BunchofPoints */
|
3 |
FirstPoint = new mPoint(); /* Allocates an instance of mPoint and invokes Constructor of mPoint to Initialize */
|
4 |
FirstPoint.dx=5;
|
5 |
FirstPoint.dy=5; /* Redefines values of instance variables dx,dy for object FirstPoint */
|
6 |
mPoint could be defined by
|
7 |
import java.awt.*;
|
8 |
public class mPoint {
-
int x, y;
-
int dx = 1, dy = 1;
-
Color color = Color.black;
|
9 |
}
|