Using Methods Flashcards
A sequence of operations that a computer program can execute on demand
Method
An executable statement that tells the computer to transfer execution to the method body
Method call
Datum that is passed to a method when it is called
Argument
Datum given back by a method when it returns from a call
Return value
What we call a method when it calls another
Caller
What is an executable statement that transfers execution to the method body?
Method call
What is a declaration that gives the information you need to use a method?
Method specification
What facts should be provided by a method specification?
A description of what it does, the data type of its return value, whether or not its static, the data type of each argument, and its identifier
Given the method specification below, which statement correctly calls the method?
double federalTax( double grossPay, int w4allowances )
double tax = federalTax( 1_300, 2 );
Given the method specification below, which statement correctly calls the method?
long currentTimeInMilliseconds( )
long time = currentTimeInMilliseconds( );
Given the method specification below, which statement correctly calls the method?
double mm( int inches)
double millimeters = mm( 2 );
Given the method specification below, which statement correctly calls the method?
void setTime( int hour, int minutes, char meridiem )
setTime( 5, 30, ‘A’ );
- Don’t put the return value when calling the method if its void in the first place
double federalTax( double grossPay, int w4allowances )
Given the method specification above, which statement best describes the statement below?
federalTax( 1_300.00, 4 );
It correctly calls the method but loses its return value.
A method with the same identifier that has several declarations, each of which takes different arguments, is said to be __________.
Overloaded
Given this Spinner class, which Java statement correctly builds a Spinner object? (There are three)
public class Spinner { private int low, high, range; public int stoppedAt; public Spinner( int lo, int hi ) { low = lo; high = hi; range = (high - low) + 1; spin( ); } public Spinner ( int hi ) { this( 1, hi ); } public Spinner( ) { this( 10 ); } public void spin( ) { stoppedAt = (int) (Math.random( ) * range + low) ; }}
Spinner s = new Spinner( ); Spinner s = new Spinner( 54 ); Spinner s = new Spinner( 0, 37 );