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 Suppose that b and c are Integer objects. A typical use of the clone method looks like this: b = (Integer) c.clone( ); Write a short clear explanation of why the (Integer) type cast is required in this typical example. A. obj = s; B. s = obj; C. s = (String) obj; D.
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 Suppose that b and c are Integer objects. A typical use of the clone method looks like this: b = (Integer) c.clone( ); Write a short clear explanation of why the (Integer) type cast is required in this typical example. 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 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. Consider the implementation of the Stack using a partially-filled array. What goes wrong if we try to store the top of the Stack at location [0] and the bottom of the Stack at the last used position of the array? A. Both peek and pop would require linear time. B. Both push and pop would require linear time. C. The Stack could not be used to check balanced parentheses. D. The Stack could not be used to evaluate postfix expressions. Write some lines of code that declares an Integer object, using the Integer wrapper class. Assign the value 42 to this object, then copy this value from the Integer object to an ordinary int variable. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of…
Attachments:
5.docx