There are two types of methods.
Math
class. (See Math and java.util.Random).
From outside the defining class, an instance method is called by
prefixing it with an object, which is then passed as an implicit
parameter to the instance method, eg, inputTF.setText("");
A static method is called by prefixing it with a class name,
eg, Math.max(i,j);.
Curiously, it can also be qualified with an object, which will be ignored,
but the class of the object will be used.
Here is a typical static method.
class MyUtils {
. . .
//================================================= mean
public static double mean(int[] p) {
int sum = 0; // sum of all the elements
for (int i=0; i<p.length; i++) {
sum += p[i];
}
return ((double)sum) / p.length;
}//endmethod mean
. . .
}
The only data this method uses or changes is from parameters (or local variables of course).
staticThe above mean() method would work just as well if
it wasn't declared static, as long as it was called from
within the same class.
If called from outside the class and it wasn't declared static, it would have to be qualified (us