Methods Continued:
Void methods
· Do not return a value, just return
VOID Ex
System.out.println(“Hello”);
voidMethod();
System.out.println(“Goodbye”);
…
static void voidMethod()
{
System.out.println(“completely void…”);
}
Param
Passing Ex
System.out.println(“Hello”);
String
phrase = “blah blah blah”;
voidMethod(phrase);
System.out.println(“Goodbye”);
…
static void voidMethod(String
phrase)
{
System.out.println(“Scope cleans teeth and variables…”);
System.out.println(phrase);
}
Why use methods?
· Reusability
· Clarity
· Abstraction / Detail Hiding
· Ease of Debugging
· Easy to Understand
· Intuitive
How to Program:
· Analyze Problem
· Design Methods
· Put it all together!