What is a method? Provide several signatures of the methods
A java method is a set of statements to perform a task. A method is placed in a class.
Signatures of methods: The name of the method, return type and the number of parameters comprise the method signature.
A method can have the following elements in it signature:
- Access specifier – public, private, protected etc. (Not mandatory)
- Access modifier – static, synchronized etc. (Not mandatory)
- Return type - void, int, String etc. (Mandatory)
- Method name – show() (Mandatory)
- With or without parameters – (int number, String name); (parenthesis are mandatory)
Example:
void showResult () { }
public double getSalary(double basicSalary) { }
public static void finalValue() { }
public static void getStateName(String city ) { }