【文章內(nèi)容簡介】
ame= Fred ,will remove them all.Answer: BQuestion 15Given:1. public class Person {2. private String name。3. public Person(String name) { = name。 }4. public boolean equals(Person p) {5. return ()。6. }7. }Which is true?A. The equals method does NOT properly override the method.B. Compilation fails because the private attribute cannot beaccessed in line 5.C. To work correctly with hashbased data structures, this class mustalso implement the hashCode method.D. When adding Person objects to a collection, the equalsmethod in line 4 will prevent duplicates.Answer: ACopyright Tarena Corporation, rights reservedQuestion 16Which two statements are true about the hashCode method? (Choosetwo.)A. The hashCode method for a given class can be used to test forobject equality and object inequality for that class.B. The hashCode method is used by the collectionclass to order the elements within that set.C. The hashCode method for a given class can be used to test forobject inequality, but NOT object equality, for that class.D. The only important characteristic of the values returned by ahashCode method is that the distribution of values must follow aGaussian distribution.E. The hashCode method is used by the collectionclass to group the elements within that set into hash buckets forswift retrieval.Answer: CEQuestion 17Given:enum Example { ONE, TWO, THREE }Which is true?A. The expressions (ONE == ONE) and (ONE) are bothguaranteed to be true.B. The expression (ONE TWO) is guaranteed to be true and(TWO) is guaranteed to be less than one.C. The Example values cannot be used in a raw 。instead, the programmer must use a .D. The Example values can be used in a , but theset will NOT be sorted because enumerated types do NOT implement.Answer: AQuestion 18Given:1. public class Score implements ComparableScore {2. private int wins, losses。3. public Score(int w, int 1) { wins = w。 losses = 1。 }4. public int getWins() { return wins。 }5. public int getLosses() { return losses。 }6. public String toString() {7. return + wins + , + losses + 。8. }9. // insert code here10. }Copyright Tarena Corporation, rights reservedWhich method will plete this class?A. public int pareTo(Object o) {/*mode code here*/}B. public int pareTo(Score other) {/*more code here*/}C. public int pare(Score s1,Score s2){/*more code here*/}D. public int pare(Object o1,Object o2){/*more code here*/}Answer: BQuestion 19Given:1. public class Test {2. public T extends Comparable T findLarger(T x, T y) {3. if((y) 0) {4. return x。5. } else {6. return y。7. }8. }9. }and:22. Test t = new Test()。23. // insert code hereWhich two will pile without errors when inserted at line 23?(Choose two.)A. Object x = (123, 456 )。B. int x = (123, new Double(456))。C. int x = (123, new Integer(456))。D. int x = (int) (new Double(123), new Double(456))。Answer: ACQuestion 20Given:1. public class Drink implements Comparable {2. public String name。3. public int pareTo(Object o) {4. return 0。5. }6. }and:20. Drink one = new Drink()。21. Drink two = new Drink()。22. = Coffee 。23. = Tea 。23. TreeSet set = new TreeSet()。24. (one)。Copyright Tarena Corporation, rights reserved25. (two)。A programmer iterates over the TreeSet and prints the name of eachDrink object.What is the result?A. TeaB. CoffeeC. CoffeeTeaD. Compilation fails.E. The code runs with no output.F. An exception is thrown at runtime.Answer: BQuestion 21Given: //Collections 中的方