More About Methods

Methods are the OOP name for functions. A method is always declared inside a class; methods can't exist outside a class. A method has this general form:

image

The parts marked “opt” in the previous example are optional, and we will deal with these in due course. An example method may look like this:

void setValue(int i) {     something = i;}

The main routine, where execution starts, is another example:

image

Arguments and parameters

What's the difference between an argument and a parameter? Here's a bit of terminology which is ...

Get Just Java™ 2 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.