public class ClassName
{
...
accessSpecifier returnType methodName(parameterType parameterName,...)
{
method body
}
...
}
|
|
Example:
|
public class Greeter
{
public String sayHello()
{
String message ="Hello,World!";
return message;
}
}
|
Purpose:
To define the behavior of a method A method definition specifies
the method name, parameters, and the statements for carrying out
the method's actions.
|