Current location - Quotes Website - Signature design - How to write java methods
How to write java methods
The syntax of this method is as follows:

Modifier returnValueType methodName (

? //method body;

}

A method definition includes a method header and a method body. Here are all the parts of the method:

Modifier:? The modifier is optional and tells the compiler how to call the method. This defines the access type of the method.

Return type:? Method can return a value. The value of returnValueType is the data type returned by the method. Some methods do not return a value to perform the required operation. In this case, the returnValueType is the keyword void.

Method name:? This is the actual name of the method. The method name and the parameter list together constitute the method signature.

Parameter:? The parameter is like a placeholder. When the method is called, a value is passed to the parameter. This value is called the actual parameter or parameter. Parameter list refers to the number of parameters of type, order and method. Parameters are optional, that is, methods can contain any parameters.

Method body:? The method body contains a collection that defines which method statements.

for instance

Public? Invalid? Display (string? A){// Method name display and parameter a

system . out . println(a); //method? body

}