Methods : Defining Method « Class Definition « Java Tutorial






  1. Methods define actions that a class's objects (or instances) can do.
  2. A method has a declaration part and a body.
  3. The declaration part consists of a return value, the method name, and a list of arguments.
  4. The body contains code that perform the action.
  5. The return type of a method can be a primitive, an object, or void.
  6. The return type void means that the method returns nothing.
  7. The declaration part of a method is also called the signature of the method.

For example, here is the getSalary method that returns a double.

public class MainClass {

  double getSalary() {
    return 0.0;

  }
}








5.3.Defining Method
5.3.1.Methods
5.3.2.Passing Objects to a Method
5.3.3.Returning From a Method