Pass Objects to Methods

Up to this point, the examples in this book have been using simple types as parameters to methods. However, it is both correct and common to pass objects to methods. For example, the following program defines a class called Block that stores the dimensions of a three-dimensional block:

Image

Image

The sameBlock( ) and sameVolume( ) methods compare the Block object passed as a parameter to the invoking object. For sameBlock( ), the dimensions of the objects are compared and true is returned only if the two blocks are the same. For ...

Get Java, A Beginner's Guide, 5th Edition, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.