QUESTION 29 Given: 05. class A { 06. void foo() throws Exception { throw new Exception(); } 07. } 08. class SubB2 extends A { 09. void foo() { System.out.println("B "); } 10. } 11. class Tester {12. public static void main(String[] args) { 13. A a = new SubB2(); 14. a.foo(); 15. } 16. } What is the result? A. B B. B, followed by an Exception. C. Compilation fails due to an error on line 9. D. Co..
QUESTION 28 Given: 1. import java.util.*; 2. public class Example { 3. public static void main(String[] args) { 4. // insert code here 5. set.add(new Integer(2)); 6. set.add(new Integer(1)); 7. System.out.println(set); 8. } 9. } Which code, inserted at line 4, guarantees that this program will output [1, 2]? A. Set set = new TreeSet(); B. Set set = new HashSet(); C. Set set = new SortedSet(); D...
QUESTION 27 A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile? A. class MinMax { E min = null; E max = null; public MinMax() {} public void put(E value) { /* store min or max */ } B. class MinMax { E min = null; E max = null; public MinMax() {} public void put(E value) { /* store min or max */ }..
QUESTION 26 Given: public class Drink implements Comparable { public String name; public int compareTo(Object o) { return 0; } } and: Drink one = new Drink();Drink two = new Drink();one.name= "Coffee"; two.name= "Tea"; TreeSet set = new TreeSet(); set.add(one); set.add(two); A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result? A. Tea B. Coffee C. C..
QUESTION 25 Given: public class Person { private name; public Person(String name) { this.name = name; } public int hashCode() { return 420; } } Which statement is true? A. The time to find the value from HashMap with a Person key depends on the size of the map. B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person. C. Inserting a second Person object int..
QUESTION 24 Given: import java.util.*;public class SortOf { public static void main(String[] args) { ArrayList a = new ArrayList(); a.add(1); a.add(5); a.add(3); Collections.sort(a); a.add(2); Collections.reverse(a); System.out.println(a); } } What is the result? A. [1, 2, 3, 5] B. [2, 1, 3, 5] C. [2, 5, 3, 1] D. [5, 3, 2, 1] E. [1, 3, 5, 2] F. Compilation fails. G. An exception is thrown at run..