
2. However, it is possible to attach methods or fields to the class itself.
These are declared with the
static modifier. This is useful, for exam-
ple, for keeping track of how many Point objects have been created:
class Point
{
public int x, y;
public static int numberOfPoints = 0;
}
Method and Parameters
In Java, the code is contained in methods. Note that there are no stand-
alone methods. Every method must be attached to a class.
The following example declares the
main() method. A method accepts para-
meters that are declared, like variables, in parentheses.
public static void main(String[] args)
{
// ...
}
Methods may return a value. The type of the return ...