header

Methods

Method

Instance Methods

Instance methods manipulate instance variables. They are the most common type of method.

Public

Public instance methods are typically invoked by an instance of a class (an object).

Declaration: public returnType methodName(parameterList)

Invocation: objectName.methodName(argumentList);

Private

Private instance methods can only be invoked from within the class itself. That is, only a method defined as part of the class can invoke a private instance method.

Declaration: private returnType methodName(parameterList)

Invocation: methodName(argumentList);

Class Methods

Class methods are invoked from the class directly rather than by an instance of the class. Class methods manipulate class variables. Since class methods cannot manipulate instance variables, they are seldom invoked by objects but they can be.

Declaration: public static returnType methodName(parameterList)

Invocation: className.methodName(argumentList);

Method Body

Local constants, if any, should be declared at the beginning of the body of the method. There is a difference of opinion about where local variables should be declared. Some believe they should be declared at the beginning after the constants. Others believe they should be declared when they are first used.

See also: Introduction to Objects

Java Tutorial: https://java.sun.com/docs/books/tutorial/java/javaOO/classdecl.html