True/False Indicate whether the
statement is true or false.
|
|
|
1.
|
Memory for an object’s data is stored as part of the class
template.
|
|
|
2.
|
Every object has its own unique identity.
|
|
|
3.
|
A client needs to know only a server’s interface.
|
|
|
4.
|
It is not possible for two variables to refer to the same object.
|
|
|
5.
|
A reference variable can be compared to the null
value.
|
|
|
6.
|
Class names must adhere to the rules for naming variables and methods.
|
|
|
7.
|
Instance variables are nearly always declared to be public.
|
|
|
8.
|
If a class template contains no constructors, the JVM provides a primitive
default constructor.
|
|
|
9.
|
You cannot call one constructor from another constructor.
|
|
|
10.
|
If the return type of a method is not void, it can be
any primitive or reference type.
|
|
|
11.
|
Method names have the same syntax as other Java identifiers.
|
|
|
12.
|
Helper methods are usually public.
|
|
|
13.
|
When an object is instantiated, it gets a complete set of fresh instance
variables
|
|
|
14.
|
You cannot have a local variable and a global variable with the same name in a
class.
|
|
|
15.
|
You should use local variables to remember information in an object.
|
Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
|
16.
|
The combining of data and behavior into a single software package is called
____.
a. | encapsulation | c. | instantiation | b. | invocation | d. | information
hiding |
|
|
|
17.
|
An object has ____ as defined by the methods of its class.
a. | a state | c. | an identity | b. | semantics | d. | behavior |
|
|
|
18.
|
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. | encapsulation | b. | information hiding | d. | instantiation |
|
|
|
19.
|
Messages that change an object’s state are called ____.
a. | modifiers | c. | mutators | b. | accessors | d. | adapters |
|
|
|
20.
|
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?
|
|
|
21.
|
Methods used to initialize a new object are called ____.
a. | initializers | c. | initiators | b. | creators | d. | constructors |
|
|
|
22.
|
Class definitions usually begin with the keyword ____, indicating that the class
is accessible to all potential clients.
a. | accessible | c. | private | b. | public | d. | global |
|
|
|
23.
|
At the root (base) of Java’s class hierarchy is a class called
____.
a. | Java | c. | Class | b. | Object | d. | Root |
|
|
|
24.
|
Constructors are activated when the keyword ____ is used.
a. | new | c. | create | b. | construct | d. | object |
|
|
|
25.
|
Which of the following represents the general form of a method?
a. | <visibility modifier> <return type> <method
name> (<parameter list>){
<implementing
code>
} | b. | <return type>
<visibility modifier> <method name> (<parameter list>){
<implementing code>
} | c. | <visibility modifier>
<method name> <return type> (<parameter list>){
<implementing code>
} | d. | <return type>
<method name> (<parameter list>){
<implementing
code>
} |
|
|
|
26.
|
If a method has a return type, its implementing code must have at least one ____
statement that returns a value of that type.
a. | end | c. | break | b. | give | d. | return |
|
|
|
27.
|
____ variables can be declared in a method to provide temporary working storage
for data in the method.
a. | Global | c. | Instance | b. | Local | d. | Internal |
|
|
|
28.
|
The scope of a ____ is all the methods in the defining class.
a. | global variable | c. | parameter | b. | local variable | d. | constant |
|
|
|
29.
|
The ____ of a variable is the period during which it can be
used.
a. | scope | c. | lifetime | b. | definity | d. | range |
|
|
|
30.
|
The ____ class includes methods for all but two mouse events, mouse motion and
mouse dragging.
a. | MouseAdapter | c. | MouseMotionAdapter | b. | MouseEvent | d. | MouseListener |
|
Completion Complete each
statement.
|
|
|
31.
|
A(n) ____________________ is a runtime entity that contains data and responds to
messages.
|
|
|
32.
|
A(n) ____________________ is a software package or template that describes the
characteristics of similar objects.
|
|
|
33.
|
An object is an instance of its class, and the process of creating a new object
is called ____________________.
|
|
|
34.
|
Because unreferenced objects cannot be used, Java deletes them during a process
called ____________________.
|
|
|
35.
|
An object has a(n) ____________________, which is another way of saying that at
any particular moment its instance variables have particular values.
|
|
|
36.
|
A client’s interactions with a(n) ____________________ are limited to
sending it messages.
|
|
|
37.
|
Methods that are used to access an object’s state are called
____________________.
|
|
|
38.
|
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.
|
|
|
39.
|
When a program attempts to run a method with an object that is null, Java throws a(n) ____________________.
|
|
|
40.
|
In Java’s class hierarchy, if class A is immediately above another class
B, we say that A is the ____________________ of B.
|
|
|
41.
|
The keywords private and public are ____________________ modifiers.
|
|
|
42.
|
Constructors with empty parameter lists are called ____________________
constructors.
|
|
|
43.
|
The visibility modifier ____________________ should be used when you want a
method to be available to clients of the defining class.
|
|
|
44.
|
A method that returns no value should have a return type of
____________________.
|
|
|
45.
|
Parameters listed in a method’s definition are called ____________________
parameters.
|
|
|
46.
|
Values passed to a method when it is invoked are called
____________________.
|
|
|
47.
|
The ____________________ of a variable is that region of the program within
which it can validly appear in lines of code.
|
|
|
48.
|
Variables declared within any compound statement enclosed in braces are said to
have ____________________ scope.
|
|
|
49.
|
The method ____________________ is used to force a refresh of any GUI component,
such as a panel.
|
|
|
50.
|
A program can detect and respond to mouse events by attaching
____________________ objects to a panel.
|
Essay
|
|
|
51.
|
What does a client
need to know in order to use a class?
|
|
|
52.
|
Why would some
variables be declared as private and others public?
|