March 2010
Beginner
760 pages
18h 51m
English
Overriding is the process of replacing an existing method in an inherited class with one more suitable for the new class. In the point and point3D examples appearing in the previous section, the distance method (presumably) computes the distance from the origin to the specified point. For a point on a two-dimensional plane, you can compute the distance using the following function:
| d = √ x2 + y2 |
However, the distance for a point in 3D space is given by this equation:
| d = √ x2 + y2 + z2 |
Clearly, if you call the distance function for point for a point3D object, you will get an incorrect answer. In the previous section, however, you saw that the P3 object calls the distance function inherited from the point class. Therefore, this would ...