QUESTION 30 Given: 1. public class Breaker { 2. static String o = ""; 3. 4. public static void main(String[] args) { 5. z: o = o + 2; 6. for (int x = 3; x
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..