Chapter 4. Structuring Code with Java Methods

As we are starting to get comfortable with Java programming, in this chapter, we will take a closer look at methods because although we know that you can call them to make them execute their code, there is more to them that haven't been discussed so far.

In this chapter, we will look at the following topics:

  • The structure of methods
  • Method overloading versus overriding
  • How methods affect our variables
  • Using our knowledge of methods to progress the Sub' Hunter game

First, let's go through a quick method recap.



A fact about methods: Almost all our code will be inside a method!

Clearly, methods are important. While this book will typically focus on the practical- getting-things-done aspect of programming ...

Get Learning Java by Building Android Games - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.