Question: MULTIPLE CHOICE 1. Suppose that obj is an Object variable and s is a String variable. Which of the following statements is a correctly-compiling widening

MULTIPLE CHOICE

1. 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.

2. 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.

3. 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.

4. 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

5. 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)); A. 0 B. 1 C. 2 D. 3

6. 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)); A. 0 B. 1 C. 2 D. 3

7. 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)); A. 0 B. 1 C. 2 D. 3

8. 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

9. 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.

10. 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

11. 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!