1.3.7 How to Use Methods

Methods are what is used to have your code actually 'do stuff'. Until now we have only focused on instantiating objects, assigning values and defining new classes/fields. Now that we have things to work with, we can use methods to alter those things.


Basic method structure looks like the following:

The method header defines what the method is and the method body defines what the method does.

So when this method is called...

...and we step into (F11) the method call...

...the debugger will hit the opening curly brace of the method.


Before any code within the method body executes we can see that the Weight of the food item is 1.

Then, once we step through the method we can see that the Weight field is reduced to 0.