Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
|
1.
|
A server’s data requirements and the implementation of its methods are
hidden from the client. This approach is referred to as ____.
a. | garbage collection | c. | information hiding | b. | instantiation | d. | encapsulation |
|
|
|
2.
|
An object has ____ as defined by the methods of its class.
a. | an identity | c. | behavior | b. | semantics | d. | a state |
|
|
|
3.
|
The combining of data and behavior into a single software package is called
____.
a. | invocation | c. | instantiation | b. | information hiding | d. | encapsulation |
|
|
|
4.
|
At the root (base) of Java’s class hierarchy is a class called
____.
a. | Object | c. | Java | b. | Class | d. | Root |
|
|
|
5.
|
Constructors are activated when the keyword ____ is used.
a. | construct | c. | object | b. | create | d. | new |
|
|
|
6.
|
____ variables can be declared in a method to provide temporary working storage
for data in the method.
a. | Global | c. | Instance | b. | Internal | d. | Local |
|
|
|
7.
|
Which of the following represents the general form of a method?
a. | <visibility modifier> <method name> <return
type> (<parameter list>){
<implementing
code>
} | b. | <return type>
<visibility modifier> <method name> (<parameter list>){
<implementing code>
} | c. | <return type>
<method name> (<parameter list>){
<implementing
code>
} | d. | <visibility modifier>
<return type> <method name> (<parameter list>){
<implementing code>
} |
|
|
|
8.
|
The ____ of a variable is the period during which it can be
used.
a. | definity | c. | lifetime | b. | range | d. | scope |
|
|
|
9.
|
If a method has a return type, its implementing code must have at least one ____
statement that returns a value of that type.
a. | return | c. | give | b. | break | d. | end |
|
|
|
10.
|
Suppose a Student class contains a method setName to set the value of a Student object’s
instance variable name, plus a method getName to access the value of name.
Consider the following code fragment:
Student s1, s2; s1 = new
Student(); s2 = new
Student(); s1.setName(“Bill”); s2.setName(“Eric”); s2 =
s1; s2.setName(“Bob”); System.out.println( s1.getName() );
What would
be displayed on the console?
|
|
|
11.
|
The scope of a ____ is all the methods in the defining class.
a. | constant | c. | global variable | b. | local variable | d. | parameter |
|
|
|
12.
|
Messages that change an object’s state are called ____.
a. | accessors | c. | adapters | b. | mutators | d. | modifiers |
|
|
|
13.
|
Methods used to initialize a new object are called ____.
a. | initiators | c. | creators | b. | initializers | d. | constructors |
|
|
|
14.
|
Class definitions usually begin with the keyword ____, indicating that the class
is accessible to all potential clients.
a. | accessible | c. | global | b. | private | d. | public |
|
Completion Complete each
statement.
|
|
|
1.
|
Because unreferenced objects cannot be used, Java deletes them during a process
called ____________________.
|
|
|
2.
|
The visibility modifier ____________________ should be used when you want a
method to be available to clients of the defining class.
|
|
|
3.
|
An object has a(n) ____________________, which is another way of saying that at
any particular moment its instance variables have particular values.
|
|
|
4.
|
A(n) ____________________ is a software package or template that describes the
characteristics of similar objects.
|
|
|
5.
|
The ____________________ of a variable is that region of the program within
which it can validly appear in lines of code.
|
|
|
6.
|
An object is an instance of its class, and the process of creating a new object
is called ____________________.
|
|
|
7.
|
A client’s interactions with a(n) ____________________ are limited to
sending it messages.
|
|
|
8.
|
The keywords private and public are ____________________ modifiers.
|
|
|
9.
|
At any time, it is possible to break the connection between a variable and the
object it references by assigning the value ____________________ to the variable.
|
|
|
10.
|
When a program attempts to run a method with an object that is null, Java throws a(n) ____________________.
|
True/False Indicate whether the
statement is true or false.
|
|
|
1.
|
If the return type of a method is not void, it can be
any primitive or reference type.
|
|
|
2.
|
A reference variable can be compared to the null
value.
|
|
|
3.
|
You should use local variables to remember information in an object.
|
|
|
4.
|
Instance variables are nearly always declared to be public.
|
|
|
5.
|
Class names must adhere to the rules for naming variables and methods.
|
|
|
6.
|
You cannot have a local variable and a global variable with the same name in a
class.
|
|
|
7.
|
Memory for an object’s data is stored as part of the class
template.
|
|
|
8.
|
A client needs to know only a server’s interface.
|
|
|
9.
|
Every object has its own unique identity.
|
|
|
10.
|
Helper methods are usually public.
|
|
|
11.
|
You cannot call one constructor from another constructor.
|
|
|
12.
|
Method names have the same syntax as other Java identifiers.
|
|
|
13.
|
When an object is instantiated, it gets a complete set of fresh instance
variables
|
|
|
14.
|
It is not possible for two variables to refer to the same object.
|
|
|
15.
|
If a class template contains no constructors, the JVM provides a primitive
default constructor.
|