Methods are reusable code blocks that only execute when called.
Defining Methods
You can create a method by typing a return type followed by the method’s name, a set of parentheses, and a code block. The
void keyword
can be used to specify that the method won’t return a value. The naming convention for methods is the same as for variables—a descriptive name with the first word in lowercase and the first letter of any subsequent words capitalized.
class MyApp
{
void myPrint()
{
System.out.println("Hello");
}
}
Calling Methods
The preceding method will simply print out a text message. ...