Suppose that obj is an Object variable and s is a String variable.
Which of the following statements is a correctly-compiling widening
conversion? Don't worry about possible run-time exceptions.
- A. obj = s;
- B. s = obj;
- C. s = (String) obj;
- D. Two or more answers are correct.
Suppose that obj is an Object variable and s is a String variable.
Which of the following statements is a correctly-compiling widening
conversion? Don't worry about possible run-time exceptions.
- A. obj = s;
- B. s = obj;
- C. s = (String) obj;
- D. Two or more answers are correct.
Suppose that obj is an Object variable and that it refers to
an Integer object. If s is a String variable, then which statement
is correct about the assignment "s = (String) obj;"?
- A. The statement will not compile.
- B. The statement will compile, but there will be a run-time exception.
- C. The statement will compile and run with no exception.
Suppose that obj is an Object variable, and consider these two
possible assignments:
obj = new Integer(42);
obj = new Double(42.0);
Both assignments compile correctly.
Select the true statement about what happens at run time:
- A. Both assignments will run with no errors, regardless of which one occurs first.
- B. Both assignments will run with no errors, but only if the Integer assignment occurs first.
- C. Both assignments will run with no errors, but only if the Double assignment occurs first.
- D. A run-time exception occurs with either statement.
Multiple Choice Section 5.2 A Bag of Objects
|
Consider this code using the ArrayBag of Section 5.2 and the
Location class from Chapter 2. What is the output?
Location i = new Location(0, 3);
Location j = new Location(0, 3);
b.add(i);
b.add(j);
System.out.println(b.countOccurrences(i));
Consider this code using the ArrayBag of Section 5.2 and the
Location class from Chapter 2. What is the output?
Location i = new Location(0, 3);
b.add(i);
b.add(i);
System.out.println(b.countOccurrences(i));
Consider this code using the ArrayBag of Section 5.2 and the
Location class from Chapter 2. What is the output?
Location i = new Location(0, 3);
Location j = new Location(0, 3);
b.add(i);
b.add(j);
// Change the Location j:
j.shift(1, 0);
System.out.println(b.countOccurrences(i));
Suppose that b is a BagArray variable from Section 5.2, and consider these two
possible statements:
b.add(new Integer(42));
b.add(new Double(42.0));
Both statements compile correctly.
Select the true statement about what happens at run time:
- A. Both statements will run with no errors, regardless of which one occurs first.
- B. The first statement will run okay, but after adding an Integer
object to the bag, you can no longer add a Double object.
- C. A run-time exception occurs with either statement.
Multiple Choice Section 5.3 JCL Collections and Nodes of Objects
|
What is a primary difference between an array and a Vector from Java's
Class Libraries:
- A. Vectors can have more than one index.
- B. Vectors can have negative integers as indexes.
- C. Vectors can have positive double numbers as indexes.
- D. Vectors grow automatically as needed.
Suppose that x and y are reference variables and a program activates
x.equals(y).
What occurs if x is the null reference?
- A. A NullPointerException occurs
- B. It always returns true.
- C. It always returns false.
- D. It returns true if y is also a null reference; otherwise it
returns false.
Multiple Choice Section 5.4 Iterators
|
What is the primary purpose of an Iterator object?
- A. To add new objects to a collection.
- B. To step through the objects of a collection one at a time.
- C. To play an audio clip.
- D. To display a graphical object.