Methods

Methods are functions of an object.

SYNTAX:

public datatype methodName(parameters...)
{
// code goes here...
}

Like fields, methods have modifiers (public/private) and data type if they return a value; otherwise, the term void is used.

A method signature is the method’s name and its parameters (e.g., myMethod { datatype, datatype…)

By convention a method name should be a verb in lowercase for the first word in the method followed by a noun or adjective (e.g., getTotal, runFast)

Overloading Methods

Like overloading constructors, Java supports OVERLOADING methods and can distinguish between methods with different method signatures but the same name IF they have different parameter lists.

Why use overload methods:

If you have a class that used various types of data (strings, integers) and it contains a method for using each data type, you would not want to use a new name for each method. Instead you pass a different argument list to each method. The class could contain multiple methods each with a different parameter list.

Overloaded methods are differentiated by the number and the type of the arguments passed into the method. However, you cannot declare more than one method with the same name and the same number and type of arguments, because the Java Compiler cannot tell them apart. In addition, the Java compiler does not consider return type when differentiating methods, so you cannot declare two methods with the SAME signature even if they have a DIFFERENT return type.