Chapter 6: Methods Flashcards
What is a method?
A group of statements that are combined in order to perform an operation.
What’s the structure of a method?
modifier returnValueType methodName(list of parameters) { //Method Body }
EXAMPLE:
public static int max(int num1, int num 2){
int result;
if (num1 > num2)
result = num1;
else
result = num1;
return result;
}
When should you use a void method versus a value-return method?
Void methods are used when the operation the method completes does not return a value. Otherwise, if you need a value then you would use a value-returning method.
What is/are a parameter(s)?
A parameter are the variables that are defined in the method header. Parameters are place holders for values that get passed to the method when invoked.
What is a call stack?
Every time a method is called and executed, the program creates a record of the parameters and variables and stores it in memory known as the call stack.
When do you use a return statement in a void method?
When you want to terminate the method at a certain point.
What is pass-by-value?
When you invoke an argument and pass the value(s) of the argument to the parameter(s).
What is method overloading?
It is when you have two or more of the exact methods, but their parameter arguments are different. Depending on what pass-by-value variable you use it will call a different method.