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

A. 0

B. exc

C. "exc" followed by an uncaught exception.

D. Compilation fails due to an error on line 4.

E. Compilation fails due to an error on line 9.

F. Compilation fails due to an error on line 11.

G. An uncaught exception is thrown with no other output.

53. Given the proper imports and given:

         81.    String in = "1234,77777,689";
         82.    Scanner sc = new Scanner(in);
         83.    sc.useDelimiter(",");
         84.    while(sc.hasNext())
         85.      System.out.print(sc.nextInt() + " ");
         86.    while(sc.hasNext())
         87.      System.out.print(sc.nextShort() + " ");

What is the result?

A. 1234 77777 689

B. Compilation fails.

C. 1234 77777 689 1234 77777 689

D. 1234 followed by an exception.

E. 1234 77777 689 followed by an exception.

F. 1234 77777 689 1234 followed by an exception.

54. Given:

         1. public class Glank implements Vonk { Jooker[] j; }
         2. abstract class Bostron { String yoodle; Bostron b; }
         3. interface Protefor { }
         4. interface Vonk extends Protefor { int x = 7; }
         5. class Jooker { Bostron b; }

Which are true? (Choose all that apply.)

A. Glanks have a Bostron.

B. Jookers implement Protefors.

C. Glanks implement Bostrons.

D. Jookers have a String.

E. Bostrons implement Vonks.

F. Bostrons have a Bostron.

55. Given that the root directory contains a subdirectory called "office" that contains some files for a Java application, if "X" and "Y" are unknown arguments, and the following command is invoked from the root directory in order to create a JAR file containing the office directory:

         jar -cf X Y

Which are true? (Choose all that apply.)

A. "X" should be the file name of the JAR file, and "Y" should be "office"

B. "X" should be "office", and "Y" should be the file name of the JAR file.

C. Specifying a file name of the JAR file here is optional.

D. If a file name is not specified here, a file named office.jar will be created.

E. The file name, if specified, must be ended with .jar extension.

F. It is required that the "office" directory must initially have a subdirectory called "META-INF"

G. All of the files other than .java and .class files must be initially placed in the META-INF directory.

56. Given a partial API:

Final class Items implements no interfaces and has one constructor:

         Items(String name, int value)

And given that you want to make collections of Items objects and sort them (using classes and interfaces in java.lang or java.util), sometimes by name, and sometimes by value, which are true? (Choose all that apply.)

A. It’s likely that you’ll use the Arrays class.

B. It’s likely that you’ll use the Collections class.

C. It’s likely that you’ll implement Comparable at least twice.

D. It’s likely that you’ll implement Comparator at least twice.

E. It’s likely that you’ll implement the compare() method at least twice.

F. It’s likely that you’ll implement the compareTo() method at least twice.

57. Given:

          1. import java.util.*;
          2. public class Drunken {
          3.   public static void main(String[] args) {
          4.     Set<Stuff> s = new HashSet<Stuff>();
          5.     s.add(new Stuff(3)); s.add(new Stuff(4)); s.add(new Stuff(4));
          6.     s.add(new Stuff(5)); s.add(new Stuff(6));
          7.     s = null;
          8.     // do more stuff
          9.   }
         10. }
         11. class Stuff {
         12.   int value;
         13.   Stuff(int v) { value = v; }
         14. }

When line 8 is reached, how many objects are eligible for garbage collection?

A. 4

B. 5

C. 6

D. 8

E. 10

F. 12

58. Given:

         1. public class Hose <E extends Hose> {
         2.   E innerE;
         3.   public static E doStuff(E e, Hose<E> e2) {
         4.     // insert code here
         5.   }
         6.   public E getE() {
         7.     return innerE;
         8. } }

Which can be inserted, independently at line 4, for the code to compile? (Choose all that apply.)

A. return e;

B. return e.getE();

C. return e2;

D. return e2.getE();

E. return new Hose().getE();

F. Compilation fails regardless of which return is inserted.

59. Given the following method signatures from ArrayList:

         boolean add(E e)
         protected void removeRange(int fromIndexInclusive, int toIndexExclusive)
         int size()

and given:

          2. import java.util.*;
          3. public class MyUtil extends ArrayList {
          4.   public static void main(String[] args) {
          5.     MyUtil m = new MyUtil();
          6.     m.add("w"); m.add("x"); m.add("y"); m.add("z");
          7.     m.removeRange(1,3);
          8.     System.out.print(m.size() + " ");
          9.     MyUtil m2 = new MyUtil2().go();
         10.     System.out.println(m2.size());
         11.   }
         12. }
         13. class MyUtil2 {
         14.   MyUtil go() {
         15.     MyUtil m2 = new MyUtil();
         16.     m2.add("1"); m2.add("2"); m2.add("3");
         17.     m2.removeRange(1,2);
         18.     return m2;
         19. } }

What is the result?

A. 1 1

B. 1 2

C. 2 1

D. 2 2

E. An exception is thrown at runtime.

F. Compilation fails due to a single error.

G. Compilation fails due to multiple errors.

60. Given:

          2. public class Hug implements Runnable {
          3.   static Thread t1;
          4.   static Hold h, h2;
          5.   public void run() {
          6.     if(Thread.currentThread().getId() == t1.getId()) h.adjust();
          7.     else h2.view();
          8.   }
          9.   public static void main(String[] args) {
         10.     h = new Hold();
         11.     h2 = new Hold();
         12.     t1 = new Thread(new Hug());
         13.     t1.start();
         14.     new Thread(new Hug()).start();
         15. } }
         16. class Hold {
         17.   static int x = 5;
         18.   synchronized void adjust() {
         19.     System.out.print(x-- + " ");
         20.     try { Thread.sleep(200); } catch (Exception e) { ; }
         21.     view();
         22.   }
         23.   synchronized void view() {
         24.     try { Thread.sleep(200); } catch (Exception e) { ; }
         25.     if(x > 0) adjust();
         26. } }

Which are true? (Choose all that apply.)

A. Compilation fails.

B. The program could deadlock.

C. The output could be: 5 4 3 2 1

D. The program could produce thousands of characters of output.

E. If the sleep() invocations were removed the chances of deadlock would decrease.

F. If the view() method was not synchronized the chances of deadlock would decrease.

Analyzing Your Results

As of this writing, a passing score on the OCP Java SE Programmer exam is 58.33 percent (35 out of 60 questions). Table 3-1 offers a rough guide to where you are in your studies.

Image

Table 3-1 What Your Score Means

If you got less than 45 questions correct, the next chapter could be a big help. We’re going to describe some small programming projects you can do that should help your understanding of the topics in the exam.

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

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