View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Declare a method

To declare a method in Java use:

visibility returnType methodName(type name1, type name2, ...) {
// code for method
}

or

visibility returnType methodName(type name1, type name2, ...)
{
// code for method
}

Where visibility is usually public or private and the returnType is
the type of thing returned from the method (or null) if nothing is returned.

Example:

public String getName() { return this.name; }


Link to this Page