6.5. Notes on Declaring and Using Methods

There are three ways to call a method:

  1. Using a method name by itself to call another method of the same class—such as maximum( number1, number2, number3 ) in line 21 of Fig. 6.3.

  2. Using a variable that contains a reference to an object, followed by a dot (.) and the method name to call a method of the referenced object—such as the method call in line 10 of Fig. 6.4, maximumFinder.determineMaximum(), which calls a method of class MaximumFinder from the main method of MaximumFinderTest.

  3. Using the class name and a dot (.) to call a static method of a class—such as Math.sqrt( 900.0 ) in Section 6.3.

Note that a static method can call only other static methods of the same class directly (i.e., using the method ...

Get Java™ How to Program, Seventh 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.