Chapter 9 Flashcards
what is a method
a module that contains a series of statements to carry out a task
what are 3 things you can do with a module
- invoke or call a method from another program/method
-any programs can contain an unlimited number of methods and a method can be called an unlimited number of times
-calling a program/method is called the method’s client
what are the parts of a method
method header - name/declaration/definition of method
method body - contains implementation (statements that carry out the tasks)
method return statement - returns to the calling method
what are local/global variables
local - declared in a method
global - known to all program modules
when you call a method from a program, what 4 things must you know?
what the method does
name of the method
type of info to sent to the method
type of return data to expect from the method
what are arguments
pass a data item into a method from a calling program
what are parameters
how the method receives the data item
when a method receives a parameter, you must provide a parameter list that includes
the type of the parameter
the local name for the parameter
what is a signature
the method’s name and parameter list
what is passed by value
a copy of a value is sent to the method and stored in a new memory location accessible to the method
each time a method executes, parameter variables listed in the method header are ____
redeclared
to create a method with multiple parameters,
separate the arguments by a comma within a method call
list the data type and local identifier for each parameter within method header’s parentheses, separating each parameter with a comma
what are sent arguments called
actual parameters
what are variables that accept the parameters in the method called
formal parameters
what does going out of scope means
a variable declared within a method ceases to exist when the method ends
to retain a value that exists when a method ends, what do you have to do
return the value from the method back to the calling method
when a method returns a value, the method must have a __
return type that matches the data type of the value that is returned
what does a return type (AKA method type) for a method do
indicates the data type of the value that the method will send back
what do you do when you want a method to return nothing
return type void
EX: Void method
although you are allowed to include multiple return statements in a method, its not recommended. Why?
because it violates structured logic ( there is only supposed to be one way in and one way out)
what is overhead
the extra resources and time required by an operation
how do you pass a single array element to a method
the same method to pass a variable to a method
how do you pass an entire array as an argument
indicate that the method parameter must be in a array (put square brackets after data type)
the arrays are then passed by reference (the method receives the actual memory address of the array and has access to it)
what is overloading a method
several methods that have the same name but are doing different tasks
what is polymorphism
the ability of a method to act appropriately according to the context
what is an ambiguous methods
situations in which the compiler cannot determine which method to use