static methods

  1. static method is a method (function) that does not operate on an object.


    int Math.round(float a) is a static method long Math.round(double a) is a static method

    static methods are just like functions in Pascal/C/C++: pass in parameters and pass out return value.

  2. Only (very minor) different is a static method in Java is contained in some class.

  3. To call a static method in Java, we must use:

    ClassName.StaticMethodName(parameters)
  4. For example:
    	Math.round(3.14);

    Special use of static method

  5. The main method of a class contains the body of the program.


    That means: when the program is run, the instructions inside the main method are executed.

    The program body does not operate on objects and therefore, the main method is always a static method:


    class MyClass { public static void main(....) { ... } }