Methods Flashcards
required elements of a method declaration
methods return type, name, pair of parenthesis and a body between braces
what is a methods signature
method name and parameter types
visibility of a method
Determines whether a method is available to other classes
public - allows any class to access the method
private - hides method from other classes
protected - lets subclasses use the method but hides the method from other classes outside the package
what is a static method
(opposed to instance method) it means you can call the method without first creating an instance of the class in which its defined (like when you create a scanner)
declaration in action
visibility/returntype/methodname/parameterlist{
statement
}
main method
calls all other methods required to run your application
invoking the method
when you write up the mthod in main, you are invoking it
getting the current year
import java.util.Calendar
int current year =
Calendar.getInstance().get(java.util.Calendar.YEAR);
delay method
– Adds a delay between output of program
private static void delay() {
try{
Thread.sleep(millisecs);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
what is passing a parameter into a method called
parameter passing