Chapter 6: Methods Flashcards

1
Q

What is a method?

A

A group of statements that are combined in order to perform an operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the structure of a method?

A
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;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When should you use a void method versus a value-return method?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is/are a parameter(s)?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a call stack?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When do you use a return statement in a void method?

A

When you want to terminate the method at a certain point.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is pass-by-value?

A

When you invoke an argument and pass the value(s) of the argument to the parameter(s).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is method overloading?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly