Exposure Java Exercises

advertisement
APCS-A Exposure Java
Name: KEY
Exercises 7.1
Date:
Period:
1.
Class methods are normally what?
Class methods are normally utility methods that do not access changing data fields.
2.
How must the methods of the Math class be accessed?
Methods in Math are class methods and must be accessed using the Math class identifier.
3.
In the statement int num; int is the _________________ and num is the _________________.
int is the type and num is the variable.
4.
In the statement Bank tom; Bank is the _________________ and tom is the _________________.
class Bank is the type and the object tom is the variable.
5.
List 4 simple data types.
int, double, char, and boolean
6.
What do simple data types store?
only a single value
7.
What 2 things do class data types store?
many values as well as methods
8.
What are the 2 categories of methods?
void and return methods
9.
What kind of values do void methods return?
void methods do not return any values.
10.
It is not possible to create large, reliable programs without being very conscious of _________________.
program design
11.
List the 3 trigonometric methods of the Math class.
sin, cos and tan
12.
If you are calling a class method, when is using the class identifier optional?
Use of the class identifier is optional if a method is called from a program statement in another method, which resides in the
same class as the method being called.
13.
If you are calling a class method, when is using the class identifier required?
Use of the class identifier is required if a method is called in a program statement that resides outside the class of the method
that is being called.
14.
What word do you NOT use when declaring a 2nd or 3rd class in a program?
public
15.
Why does program Java0705.java not compile?
Methods of the Address class are called from the main method, but without the Address class identifier.
16.
If you are in the main method, and you want to call a hiss method from a Boo class, what would be the exact syntax?
Boo.hiss();
17.
What Applet method controls the graphics display of an Applet in the same manner that the main method controls the
sequence in an application program?
The paint method
7/7/2007
18.
Output to the monitor requires the use of a _____________________ object.
Graphics
19.
If you select to divide the graphics output into multiple modules you need to make sure that you do what?
Pass the Graphics object to the other modules.
20.
Common methods should be placed in a ____________________.
class
21.
Compare the paint methods of Java0708.java and Java0709.java.
In the latter program, why are all of the method calls preceded with “House.”?
These methods are all in the House class.
22.
Refer to the previous question. Why was this not necessary in the former program?
All of the methods were in the same class.
23.
List 2 methods that do NOT require any parameters?
println() and nextInt()
24.
The key difference between creating no-parameter methods and parameter methods is the ___________________________.
parameter declaration
25.
All method declarations have an identifier followed by _____________________.
parentheses
26.
What is the difference between an actual parameter and a formal parameter?
Actual parameters are in the method call.
Formal parameters are in the method heading.
27.
An actual parameter can be several different things. List 5 examples.
It is possible to use a constant only, a variable only, an expression with constants only, an expression with a variable and a
constant and a method call that returns the appropriate value.
28.
Look at program Java0714.java. What is wrong with Line 1?
Actual parameters should not have data types.
29.
Look at program Java0714.java. What is wrong with Line 2?
Every formal parameter requires a data type.
30.
If a method has several parameters, do they all need to be of the same type?
No
31.
The number of parameters in the method call must match what?
the number of parameters in the method heading
32.
The corresponding actual parameters in the method call must be the same ________ as the formal parameters in the heading.
type
33.
The _____________________ of the ____________________ in the ____________________ must match the sequence of
the formal parameters in the heading.
sequence of the actual parameters in the method call
34.
Can the actual parameter identifiers be the same as the formal parameter identifiers?
Yes
35.
Can the actual parameter identifiers be the different from as the formal parameter identifiers?
Yes
7/7/2007
Download