touque.ca > Education Commons > Java > Resources

Methods

Methods are subprograms which perform a task and/or return a value.

Methods follow into one of two main categories:

  1. static: not associated with an object
  2. instance: associated with an object

Static methods have the keyword static in their signatures (headers); instance methods do not. Methods which return a value identify the datatype of that value in their signatures; methods which return no value substitute the keyword void instead. For example:

public static void main(String[] argument)
This method is not associated with an object and does not return a value. It requires a string array as its sole parameter.

public static int sum(int number1, int number2)
This method is not associated with an object and it returns an integer value. It requires two integer parameters.

public double getBalance()
This method is associated with an object, which means it must be called against an object. This method returns a double value; it accepts no parameters.

touque.ca > Education Commons > Java > Resources

[This page last updated 2020-12-23 at 12h13 Toronto local time.]