Web hosting services - 488 Object-Oriented Programming Chapter 9 1 // Fig.

488 Object-Oriented Programming Chapter 9 1 // Fig. 9.23: Point.java 2 // Definition of class Point 3 4 public class Point extends Shape { 5 protected int x, y; // coordinates of the Point 6 7 // no-argument constructor 8 public Point() 9 { 10 setPoint( 0, 0 ); 11 } 12 13 // constructor 14 public Point( int xCoordinate, int yCoordinate ) 15 { 16 setPoint( xCoordinate, yCoordinate ); 17 } 18 19 // set x and y coordinates of Point 20 public void setPoint( int xCoordinate, int yCoordinate ) 21 { 22 x = xCoordinate; 23 y = yCoordinate; 24 } 25 26 // get x coordinate 27 public int getX() 28 { 29 return x; 30 } 31 32 // get y coordinate 33 public int getY() 34 { 35 return y; 36 } 37 38 // convert point into String representation 39 public String toString() 40 { 41 return “[”+ x + “, ” + y + “]”; 42 } 43 44 // return shape name 45 public String getName() 46 { 47 return “Point”; 48 } 49 50 } // end class Point Fig. 9.23 Pointsubclass of abstract class Shape. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply