Methods are subprograms which perform a task and/or return a value.
Methods follow into one of two main categories:
- static: not associated with an object
- 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.
[This page last updated 2020-12-23 at 12h13 Toronto local time.]
© 2007–2021 Hersch, Bear & Company Limited. All rights reserved. “Grammar Authority,” “grammarauthority.com,” “touque.ca,” and “Canada’s Thinking Cap” are trademarks of Hersch, Bear & Company Limited. All other trademarks and copyrights are the property of their respective owners.