O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a Subclass

To see an example of inheritance at work, in the next project you create a class called Point3D that represents a point in three-dimensional space. You can express a two-dimensional point with an (x,y) coordinate. Applets use an (x,y) coordinate system to determine where text and graphics should be displayed. Three-dimensional space adds a third coordinate, which can be called z.

The Point3D class of objects should do three things:

• Keep track of an object’s (x,y,z) coordinate

• Move an object to a new (x,y,z) coordinate when needed

• Move an object by a certain amount of x, y, and z values as needed

Java already has a standard class that represents two-dimensional points; it’s called Point.

It has two integer variables called ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required