What is the result? (Choose all that apply.)

A. Compilation fails.

B. fa father ch child child

C. gf father gf child child

D. fa grandf ch grandf father

E. gf grandf gf grandf father

F. An exception is thrown at runtime.

55. Given:

          1. class MyClass { }

And given that MyClass2 has properly overridden equals() and hashCode(), objects from which classes make good hashing keys? (Choose all that apply.)

A. MyClass

B. MyClass2

C. java.lang.String

D. java.lang.Integer

E. java.lang.StringBuilder

56. Given:

          2. public class Buffalo {
          3.   static int x;
          4.   int y;
          5.   public static int getX() { return x; }
          6.   public static void setX(int newX) { x = newX; }
          7.   public int getY() { return y; }
          8.   public void setY(int newY) { y = newY; }
          9. }

Which lines of code need to be changed to make the class thread safe? (Choose all that apply.)

A. Line 2

B. Line 3

C. Line 4

D. Line 5

E. Line 6

F. Line 7

G. Line 8

57. Given:

          2. class Animal { }
          3. class Dog extends Animal { }
          4. class Cat extends Animal { }
          5. public class Mixer<A extends Animal> {
          6.   public <C extends Cat> Mixer<? super Dog> useMe(A a, C c) {
          7.     //Insert Code Here
          8. } }

Which, inserted independently at line 7, compile? (Choose all that apply.)

A. return null;

B. return new Mixer<Dog>();

C. return new Mixer<Animal>();

D. return new Mixer<A>();

E. return new Mixer<a>();

F. return new Mixer<c>();

58. Given:

          2. class Chilis {
          3.   Chilis(String c, int h) { color = c; hotness = h; }
          4.   String color;
          5.   private int hotness;
          6.   public boolean equals(Object o) {
          7.     Chilis c = (Chilis)o;
          8.     if(color.equals(c.color) && (hotness == c.hotness)) return true;
          9.     return false;
         10.  }
         11.  // insert code here
         12. }

Which, inserted independently at line 11, fulfill the equals() and hashCode() contract for Chilis? (Choose all that apply.)

A. public int hashCode() { return 7; }

B. public int hashCode() { return hotness; }

C. public int hashCode() { return color.length(); }

D. public int hashCode() { return (int)(Math.random() * 200); }

E. public int hashCode() { return (color.length() + hotness); }

59. Given the proper import(s), and this code in a method:

          4.     List<String> x = new LinkedList<String>();
          5.     Set<String> hs = new HashSet<String>();
          6.     String[] v = {"a", "b", "c", "b", "a"};
          7.     for(String s: v) {
          8.       x.add(s); hs.add(s);
          9.     }
         10.     System.out.print(hs.size() + " " + x.size() + " ");
         11.     HashSet hs2 = new HashSet(x);
         12.     LinkedList x2 = new LinkedList(hs);
         13.     System.out.println(hs2.size() + " " + x2.size());

What is the result?

A. 3 3 3 3

B. 3 5 3 3

C. 3 5 3 5

D. 5 5 3 3

E. 5 5 5 5

F. Compilation fails.

G. An exception is thrown at runtime.

60. Given the proper import(s), and given:

          4. public static void main(String[] args) {
          5.   List<Integer> x = new ArrayList<Integer>();
          6.   x.add(new Integer(3));
          7.   doStuff(x);
          8.   for(Integer i: x)
          9.     System.out.print(i + " ");
         10.  }
         11.  static void doStuff(List y) {
         12.    y.add(new Integer(4));
         13.    y.add(new Float(3.14f));
         14.  }

What is the result? (Choose all that apply.)

A. Compilation fails.

B. The output will be "4 "

C. The output will be "3 4 "

D. The output will be "3 4 3.14 "

E. The output will be "3 3.14 4 "

F. The output will be "3 4 ", followed by an exception.

G. An exception will be thrown before any output is produced.

Analyzing Your Results

Table 5-1 assumes a passing score on the OCP Java SE Programmer exam is 58.33 percent (35 out of 60 questions). If you got less than 45 questions correct on the first full exam, you should have done better on this exam than on the first. If your score didn’t improve, we would advise you to do more studying before taking any more practice exams. Practice exams are a crucial part of preparing for the OCP Java SE Programmer exam, but they are only one component of a successful plan.

Image

TABLE 5-1 What Your Score Means

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset