A Collections sorta areverse int result 6 B Comparator

A collections sorta areverse int result 6 b comparator

This preview shows page 84 - 87 out of 101 pages.

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); Answer: C Question 190 Given: 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 here
Image of page 84
What, 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); Answer: B Question 191 Given 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 here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of 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); Answer: C Question Given 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 here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils? A. process(bytes); B. BitUtils.process(bytes); C. app.BitUtils.process(bytes); D. util.BitUtils.process(bytes);
Image of page 85
E. import util.BitUtils. *; process(bytes); F. SomeApp cannot use the process method in BitUtils. Answer: F Question 193 Given 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? A. text B. <msg>text</msg> C. An exception is thrown at runtime. D. Compilation fails because of an error in line 2 of XMLMessage. E. Compilation fails because of an error in line 3 of XMLMessage. Answer: E Question 194 Given a file GrizzlyBear.java: 1. package animals.mammals; 2. 3. public class GrizzlyBear extends Bear { 4. void hunt() { 5. Salmon s = findSalmon(); 6. s.consume(); 7. } 8. } and another file, Salmon.java: 1. package animals.fish; 2. 3. public class Salmon extends Fish { 4. void consume() { /* do stuff */ } 5. } Assume both classes are defined in the correct directories for theft packages, and that the Mammal class correctly defines the findSalmon() method. Which two changes allow this code to compile correctly? (Choose two.) A. add public to the start of line 4 in Salmon.java
Image of page 86
Image of page 87

You've reached the end of your free preview.

Want to read all 101 pages?

  • Fall '15
  • Muler
  • Madrid Metro, Metropolitana di Napoli, class a, Osaka Municipal Subway, public class, public static void

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture