Chapter 6 Methods Flashcards

1
Q

What is a method and what are they used for:

A

A method is a sequence of program statements that have a specific task that they perform.

Methods can be used to define reusable code, organize and simplify coding, and make code easier to maintain.

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

Creating a method involves writing the statements and providing a method declaration with:

A
  1. Method name (following the same rule as identifyers)
  2. List of inputs (called parameters) and their data types
  3. The output (return value) type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Defining a method syntax:

A

modifier returnValueType methodName(list of parameters){
//method body
return returnValue;
}

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

Calling (or invoking) a method involves

A
  1. Providing the name of the method
  2. Providing the arguments (inputs) if any
  3. Providing variable to store the outputs (if any)

Syntax:
variable = methodName(list of arguments);

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

A method is a:

A

A method is a collection of statements that are grouped together to perform an operation

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

Method signature

A

Refers to the combination of the method name and the parameter list

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

Formal parameters

A

The variables defined in the method header are known as the formal parameters

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

Actual parameters

A

When a method is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument.

x,y in int z = max (x, y);

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

Return Type Value 14

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