Chapter 10

Methods

In Java all programs are built with classes, which means there is at least one class. Further, every program must have at least one method, the main() method. That’s it. Beyond that, you don’t need to create other methods. But, without methods, often your code will contain a lot of duplicate instructions.

In this chapter, you will learn how to create your own methods, invoking methods, accepting parameters, and finally returning values from methods.