Declaring a method has four parts: a return type (use void when it returns nothing), a name, a pair of parentheses (), and a body in braces { }. void means the method does its work but hands back no value.
void
()
{ }
void printLine() { System.out.println("-----"); }
Return type void, name printLine, empty (), and a body that prints a row of dashes. Calling printLine() runs that one line.
printLine
printLine()
▶ Try it: printLine() is defined for you and prints a row of dashes. Run this, then change how many times it is called.
In void printLine() { ... }, what does void mean?
void printLine() { ... }
Put the parts of the method header in the order they are written: void printLine().
void printLine()
Match each part of a method to its role.
True or false?
Type exactly what this program prints.
public class Main { static void star() { System.out.println("*"); } public static void main(String[] args) { star(); } }