Index
Metodi
Declaring a Java Method
The syntax to declare a method is:
modifier static returnType nameOfMethod (type parameter1, type parameter2, ...) {
// method body
}Tip
returnType- It specifies what type of value a method returns For example if a method has anintreturn type then it returns an integer value.methodName- It is an identifier that is used to refer to the particular method in a programmodifier- It defines access types whether the method is public, private, and so on. To learn more, visit Java - Access Modifierparameter1/parameter2- These are values passed to a method. We can pass any number of arguments to a method.static- If we use thestatickeyword, it can be accessed without creating objects.
- For example, the
sqrt()method of standard Java Math class is static. Hence, we can directly callMath.sqrt()without creating an instance ofMathclass.
oss
- If the method does not return a value, its returnType is
void.- il
modifierdi metodo è tipicamente pubblico, ovvero visibile a tutti