Chapter 9. Methods

In Chapter 8 we learned that a class can declare variables. A class can also declare methods. A method, in the simplest way of looking at it, is a named block of code that can be called from another part of a program. In non-object-oriented programming languages, such as C or Fortran, the method (or function or subroutine) is the basic building block of the program. Methods are used to divide the program into functional units. There are no access restrictions associated with a C or Fortran method. It can be called directly from anywhere in the program.

In Java, methods are an integral part of the object-oriented framework, but they are not the basic building block of a Java program—the class serves that function. Java methods ...

Get Technical Java™: Developing Scientific and Engineering Applications 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.