A 0 B 1 C 2 D a E b F c G The result is undefined Question 188 Given 1 import

# A 0 b 1 c 2 d a e b f c g the result is undefined

• savingthingsformyself
• 102

This preview shows page 85 - 88 out of 102 pages.

A. 0B. 1C. 2D. aE. bF. cG. The result is undefined.Question 188Given:1. import java.util.*;2.3. public class LetterASort {4. public static void main(String[] args) {5. ArrayList<String> strings = new ArrayList<String>();6. strings.add(’aAaA”);7. strings.add(”AaA”);8. strings.add(’aAa”);9. strings.add(”AAaa”);10. Collections.sort(strings);11. for (String s: strings) { System.out.print(s + “ “); }12. }13. }What is the result?A. Compilation fails.B. aAaA aAa AAaa AaAC. AAaa AaA aAa aAaAD. AaA AAaa aAaA aAaE. aAa AaA aAaA AAaaF. An exception is thrown at runtime.Question 189Given:ArrayList a = new ArrayList();containing the values {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”}Which code will return 2?A. Collections. sort(a, a.reverse());int result = Collections.binarySearch(a, “6”);B. Comparator c = Collections.reverseOrder();Collections.sort(a, c);
int result = Collections.binarySearch(a, “6”);C. Comparator c = Collections.reverseOrder();Collections.sort(a, c);int result = Collections.binarySearch(a, “6”,c);D. Comparator c = Collections.reverseOrder(a);Collections.sort(a, c);int result = Collections.binarySearch(a, “6”,c);E. Comparator c = new InverseComparator(new Comparator());Collections.sort(a);int result = Collections.binarySearch(a, “6”,c);Question 190Given:34. HashMap props = new HashMap();35. props.put(”key45”, “some value”);36. props.put(”key12”, “some other value”);37. props.put(”key39”, “yet another value”);38. Set s = props.keySet();39. // insert code hereWhat, inserted at line 39, will sort the keys in the props HashMap?A. Arrays.sort(s);B. s = new TreeSet(s);C. Collections.sort(s);D. s = new SortedSet(s);Question 191Given classes defined in two different files:1. package util;2. public class BitUtils {3. public static void process(byte[]) { /* more code here */ }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. util.BitUtils.process(bytes);D. SomeApp cannot use methods in BitUtils.E. import util.BitUtils.*; process(bytes);
QuestionGiven classes defined in two different files:1. package util;2. public class BitUtils {3. private static void process(byte[] b) { }4. }1. package app;2. public class SomeApp {3. public static void main(String[] args) {4. byte[] bytes = new byte[256];5. // insert code here6. }7. }What is required at line 5 in class SomeApp to use the process methodof BitUtils?A. process(bytes);B. BitUtils.process(bytes);C. app.BitUtils.process(bytes);D. util.BitUtils.process(bytes);E. import util.BitUtils. *; process(bytes);F. SomeApp cannot use the process method in BitUtils.Question 193Given classes defined in two different files:1. package packageA;2. public class Message {3. String getText() { return “text”; }4. }and:1. package packageB;2. public class XMLMessage extends packageA.Message {3. String getText() { return “<msg>text</msg>”; }4. public static void main(String[] args) {5. System.out.println(new XMLMessage().getText());6. }7. }What is the result of executing XMLMessage.main?