Suppose we have a class that can represent two-dimensional
shapes:
0260: public class Shape // Shape.java
0261: {
0262: private int iX, iY;
0263: public Shape(int pX, int pY)
0264: {
0265: iX = pX; iY = pY;
0266: }
0267: public int getX()
0268: {
0269: return iX;
0270: }
0271: public int getY()
0272: {
0273: return iY;
0274: }
0275: public Shape translate(int pX, int pY)
0276: {
0277: return new Shape(iX + pX, iY + pY);
0278: }
0279: public boolean equals(Object pObject)
0280: {
0281: return iX==((Shape)pObject).iX && iY==((Shape)pObject).iY;
0282: }
0283: public String toString()
0284: {
0285: return iX + ":" + iY;
0286: }
0287: }