Glossary Flashcards
1) a method
A method is a part of a class and contains a particular set of i___________ .
Normally a method will perform a single well-defined t______.
Methods allow a programer to m____________ a program: to break up a complex program into simpler parts.
instructions
task
modularize
2) The first line, which declares the method, is called ________________
Example
static void displayMessage() ( This line)
{
System.out.println(“Please note that all information supplied is confidential”);
System.out.println(“No personal details will be shared with any third party”);
}
A method header
3) This m______ h_______ consists of three words:
static void displayMessage()
(The name that we have given to our method)
method header
4) static
Methods that have been d________ as static (such as main) can only call other methods in the class
if they too are s______.
declared
static
5) void
Methods can return information once they t_________, but they don’t have to.
If a method is just doing something simple like displaying a message, then it will not be returning a value.
If a method will not be returning a value, we declare it as v_____.
terminate
void
6) The naming convention for methods is ____________________
lower camel case
7) True or False
A method can only be called from within the main method.
False
A method can be called by the main method, but it can also be called by any other method.
The called method could in turn call yet another method. This would result in a number of methods being “chained”.
8) Methods that are NOT void!
Look at the following method header.
static void displayQuetion( )
Is this method going to return a value?
No. The brackets are empty, and it has therefore been named ‘void’.
9) Study the following method header
static double addTax(double priceIn, double taxIn)
Is this method going to return a value?
Yes!
10) What value will be returned by the following method?
static double addTax(double priceIn, double taxIn)
{
return priceIn * (1 + taxIn/100);
}
The new price of the item, including tax.
11) Why do we have the word ‘double’ instead of ‘void’?
static double addTax(double priceIn, double taxIn)
{
return priceIn * (1 + taxIn/100);
}
Because we will be returning a value as a double, e.g. £3.50
The variable ‘price’, which will have been declared earlier in the program will have been declared as a double.
12) The variables declared in the (brackets of a method) are called:
f______________ p_______________ of the method.
formal parameters
13) Which suffix is conventionally added to variable names within a method’s formal parameters?
e.g. ‘tax’ would become…
-IN
taxIN
14) return
Study the following method:
static double addTax(double priceIn, double taxIn)
{
return priceIn * (1 + taxIn/100);
}
The word ‘return’ in the body of the method serves two very important functions:
1) It t____________ the method
2) It s__________ b_________ a value
terminates
sends back
Notice, the return statement can also perform calculations!
e.g. return priceIn * (1 + taxIn/100);
15) Local Variables
As we learned in week 1, variables are only visible within the curly braces in which they were declared.
So, the variables declared inside particular sets of brackets are called
l_________ v____________
local variables