Thursday, December 27, 2012

EXAM E


QUESTION 1

Given:

import java.util.Date;
import java.text.DateFormat;
DateFormat df;
Date date = new Date();
//insert code here Linea 23
String s = df.format(date);

Which code fragment, inserted at line 23, allows the code to compile?

A. df = new DateFormat();
B. df = Date.getFormat();
C. df = date.getFormat();
D. df = DateFormat.getFormat();
E. df = DateFormat.getInstance();

Answer: E
Section: All

Explanation/Reference:

QUESTION 2

Given:

1. public class BuildStuff {
2. public static void main(String[] args) {
3. Boolean test = new Boolean(true);
4. Integer x = 343;
5. Integer y = new BuildStuff().go(test, x);
6. System.out.println(y);
7. }
8. int go(Boolean b, int i) {
9. if(b) return (i/7);
10. return (i/49);
11. }
12. }

What is the result?

A. 7
B. 49
C. 343
D. Compilation fails.
E. An exception is thrown at runtime.

Answer: B
Section: All

Explanation/Reference:

QUESTION 3

Given:

import java.io.*;
public class Forest implements Serializable {
     private Tree tree = new Tree();
     public static void main(String [] args) {
          Forest f = new Forest();
          try {
       
              FileOutputStream fs = new FileOutputStream("Forest.ser");
              ObjectOutputStream os = new ObjectOutputStream(fs);
              os.writeObject(f); os.close();
          } catch (Exception ex) { ex.printStackTrace(); }
     }
}
class Tree { }

What is the result?

A. Compilation fails.
B. An exception is thrown at runtime.
C. An instance of Forest is serialized.
D. An instance of Forest and an instance of Tree are both serialized.

Answer: B
Section: All

Explanation/Reference:

QUESTION 4

Which capability exists only in java.io.FileWriter?

A. Closing an open stream.
B. Flushing an open stream.
C. Writing to an open stream.
D. Writing a line separator to an open stream.

Answer: D
Section: All

Explanation/Reference:

QUESTION 5

Given:

1. import java.io.*;
2.
3.
4.
5.
6. public class Talk {
7. public static void main(String[] args) {
8. Console c = new Console();
9. String pw;
10. System.out.print("password: ");
11. pw = c.readLine();
12. System.out.println("got " + pw);
13. }
14. }

If the user types the password aiko when prompted, what is the result?

A. password:  got
B. password:  got aiko
C. password: aiko got aiko
D. An exception is thrown at runtime.
E. Compilation fails due to an error on line 8.

Answer: E
Section: All

Explanation/Reference:

QUESTION 6

Given:

1. public class LineUp {
2. public static void main(String[] args) {
3. double d = 12.345;
4. // insert code here
5. }
6. }

Which code fragment, inserted at line 4, produces the output | 12.345|?

A. System.out.printf("|%7d| \n", d);
B. System.out.printf("|%7f| \n", d);
C. System.out.printf("|%3.7d| \n", d);
D. System.out.printf("|%3.7f| \n", d);
E. System.out.printf("|%7.3d| \n", d);
F. System.out.printf("|%7.3f| \n", d);

Answer: F
Section: All

Explanation/Reference:

QUESTION 7

Given:

11. String test = "Test A. Test B. Test C.";
12. // insert code here
13. String[] result = test.split(regex);

Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?

A. String regex = "";
B. String regex = " ";
C. String regex = ".*";
D. String regex = "\\s";
E. String regex = "\\.\\s*";
F. String regex = "\\w[ \.] +";

Answer: E
Section: All

Explanation/Reference:

QUESTION 8

Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?

A. Compilation fails because of an error in line 3.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 9.
D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.
E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.
F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

Answer: F
Section: All

Explanation/Reference:

QUESTION 9

Click the Exhibit button.
What is the result?

Add caption
A. Value is: 8
B. Compilation fails.
C. Value is: 12
D. Value is: -12
E. The code runs with no output.
F. An exception is thrown at runtime.

Answer: A
Section: All

Explanation/Reference:

QUESTION 10

Given:

public class Base {
     public static final String FOO = "foo";
   
     public static void main(String[] args) {
          Base b = new Base();
          Sub s = new Sub();
          System.out.print(Base.FOO);
          System.out.print(Sub.FOO);
          System.out.print(b.FOO);
          System.out.print(s.FOO);
          System.out.print(((Base) s).FOO);
     }
}
class Sub extends Base {
     public static final String FOO = "bar";
}

What is the result?

A. foofoofoofoofoo
B. foobarfoobarbar
C. foobarfoofoofoo
D. foobarfoobarfoo
E. barbarbarbarbar
F. foofoofoobarbar
G. foofoofoobarfoo

Answer: D
Section: All

Explanation/Reference:

QUESTION 11

Given:

1. class Mammal {
2. }
3.
4. class Raccoon extends Mammal {
5. Mammal m = new Mammal();
6. }
7.
8. class BabyRaccoon extends Mammal {
9. }
10.
Which four statements are true? (Choose four.)

A. Raccoon is-a Mammal.
B. Raccoon has-a Mammal.
C. BabyRaccoon is-a Mammal.
D. BabyRaccoon is-a Raccoon.
E. BabyRaccoon has-a Mammal.
F. BabyRaccoon is-a BabyRaccoon.

Answer: ABCF
Section: All

Explanation/Reference:

QUESTION 12

Given:

interface A { void x(); }
class B implements A { public void x() {} public void y() {} }
class C extends B { public void x() {} }

And:

java.util.List<A> list = new java.util.ArrayList<A>();
list.add(new B());
list.add(new C());
for (A a : list) {
     a.x();
     a.y(); //Linea 25
}

What is the result?

A. The code runs with no output.
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 20.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 23.
F. Compilation fails because of an error in line 25.

Answer: F
Section: All

Explanation/Reference:

QUESTION 13

Given:

1.
2. public class Hi {
3. void m1() { }
4. protected void() m2 { }
5. }
6. class Lois extends Hi {
7. // insert code here
8. }

Which four code fragments, inserted independently at line 7, will compile? (Choose four.)

A. public void m1() { }
B. protected void m1() { }
C. private void m1() { }
D. void m2() { }
E. public void m2() { }
F. protected void m2() { }
G. private void m2() { }

Answer: ABEF
Section: All

Explanation/Reference:

QUESTION 14

Which four statements are true? (Choose four.)

A. Has-a relationships should never be encapsulated.
B. Has-a relationships should be implemented using inheritance.
C. Has-a relationships can be implemented using instance variables.
D. Is-a relationships can be implemented using the extends keyword.
E. Is-a relationships can be implemented using the implements keyword.
F. The relationship between Movie and Actress is an example of an is-a relationship.
G. An array or a collection can be used to implement a one-to-many has-a relationship.

Answer: CDEG
Section: All

Explanation/Reference:

QUESTION 15

Given:

public class Hello {
     String title;
     int value;
   
     public Hello() {
          title += " World";
     }
   
     public Hello(int value) {
          this.value = value;
          title = "Hello";
          Hello();
     }
}

and:

Hello c = new Hello(5);
System.out.println(c.title);

What is the result?

A. Hello
B. Hello World
C. Compilation fails.
D. Hello World 5
E. The code runs with no output.
F. An exception is thrown at runtime.

Answer: C
Section: All

Explanation/Reference:

QUESTION 16

Given:
1. package geometry;
2.
3. public class Hypotenuse {
4. public InnerTriangle it = new InnerTriangle();
5.
6. class InnerTriangle {
7. public int base;
8. public int height;
9. }
10. }
Which statement is true about the class of an object that can reference the variable base?

A. It can be any class.
B. No class has access to base.
C. The class must belong to the geometry package.
D. The class must be a subclass of the class Hypotenuse.

Answer: C
Section: All

Explanation/Reference:

QUESTION 17

Click the Exhibit button.

1. public class A {
2.
3. private int counter = 0;
4.
5. public static int getInstanceCount(){
6. return counter;
7. }
8.
9. public A(){
10. counter++;
11. }
12. }
13.

Given this code from Class B:

A a1 = new A();
A a2 = new A();
A a3 = new A();
System.out.println(A.getInstanceCount());

What is the result?

A. Compilation of class A fails.
B. Line 28 prints the value 3 to System.out.
C. Line 28 prints the value 1 to System.out.
D. A runtime error occurs when line 25 executes.
E. Compilation fails because of an error on line 28.

Answer: A
Section: All

Explanation/Reference:

QUESTION 18

Given:

10. interface Data { public void load(); }
11. abstract class Info { public abstract void load(); }

Which class correctly uses the Data interface and Info class?

A. public class Employee extends Info implements Data { public void load() { /
   *do something*/ }
   }
B. public class Employee implements Info extends Data { public void load() { /
   *do something*/ }
   }
C. public class Employee extends Info implements Data public void load(){ /*do
   something*/ }
   public void Info.load(){ /*do something*/ }
   }
D. public class Employee implements Info extends Data { public void Data.load()
   { /*do something*/ }
   public void load(){ /*do something*/ }
   }
E. public class Employee implements Info extends Data { public void load(){ /
   *do something*/ }
   public void Info.load(){ /*do something*/ }
   }
F. public class Employee extends Info implements Data{ public void Data.load()
   { /*do something*/ }
   public void Info.load() { /*do something*/ }
   }
 
Answer: A
Section: All

Explanation/Reference:

QUESTION 19

Given:

1. class Alligator {
2. public static void main(String[] args) {
3. int[] x[] = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
4. int[][] y = x;
5. System.out.println(y[2][1]);
6. }
7. }

What is the result?

A. 2
B. 3
C. 4
D. 6
E. 7
F. Compilation fails.

Answer: E
Section: All

Explanation/Reference:

QUESTION 20

Given:

abstract class C1 {
public C1() { System.out.print(1); }
}
class C2 extends C1 {
public C2() { System.out.print(2); }
}
class C3 extends C2 {
public C3() { System.out.println(3); }
}
public class Ctest {
public static void main(String[] a) { new C3(); }
}

What is the result?

A. 3
B. 23
C. 32
D. 123
E. 321
F. Compilation fails.
G. An exception is thrown at runtime.

Answer: D
Section: All

Explanation/Reference:

QUESTION 21

Given:
class One {
     public One foo() {
          return this;
     }
}
class Two extends One {
     public One foo() {
          return this;
     }
}
class Three extends Two {
     // insert method here
}
Which two methods, inserted individually, correctly complete the Three class? (Choose two.)

A. public void foo() {}
B. public int foo() { return 3; }
C. public Two foo() { return this; }
D. public One foo() { return this; }
E. public Object foo() { return this; }

Answer: CD
Section: All

Explanation/Reference:

QUESTION 22

Which two classes correctly implement both the java.lang.Runnable and the java.lang.
Cloneable interfaces? (Choose two.)

A. public class Session implements Runnable, Cloneable {
        public void run();    
        public Object clone();
   }
B. public class Session   extends Runnable, Cloneable {
        public void run() { /* do something */ }
        public Object clone() { /* make a copy */ }
C. public class Session  implements Runnable, Cloneable {
        public void run() { /* do something */ }
        public Object clone() { /* make a copy */ }
D. public abstract class Session  implements Runnable, Cloneable {
        public void run() { /* do something */ }
        public Object clone() { /*make a copy */ }
E. public class Session  implements Runnable, implements Cloneable {
        public void run() { /* do something */ }
        public Object clone() { /* make a copy */ }
     
Answer: CD
Section: All

Explanation/Reference:

QUESTION 23

Given:

public interface A { public void m1(); }
class B implements A { }
class C implements A { public void m1() { } }
class D implements A { public void m1(int x) { } }
abstract class E implements A { }
abstract class F implements A { public void m1() { } }
abstract class G implements A { public void m1(int x) { } }

What is the result?

A. Compilation succeeds.
B. Exactly one class does NOT compile.
C. Exactly two classes do NOT compile.
D. Exactly four classes do NOT compile.
E. Exactly three classes do NOT compile.

Answer: C
Section: All

Explanation/Reference:

QUESTION 24

Given:

class Line {
     public class Point {
          public int x, y;
     }   
     public Point getPoint() {
          return new Point();
     }
}
class Triangle {
     public Triangle() {
          // insert code here
     }
}

Which code, inserted at line 16, correctly retrieves a local instance of a Point object?

A. Point p = Line.getPoint();
B. Line.Point p = Line.getPoint();
C. Point p = (new Line()).getPoint();
D. Line.Point p = (new Line()).getPoint();

Answer: D
Section: All

Explanation/Reference:

QUESTION 25

Given:

1. class TestA {
2. public void start() { System.out.println("TestA"); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println("TestB"); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }

What is the result?

A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.

Answer: B
Section: All

Explanation/Reference:

QUESTION 26

Given:

11. public static void main(String[] args) {
12. Object obj = new int[] { 1, 2, 3 };
13. int[] someArray = (int[])obj;
14. for (int i : someArray) System.out.print(i + " ");
15. }

What is the result?

A. 123
B. Compilation fails because of an error in line 12.
C. Compilation fails because of an error in line 13.
D. Compilation fails because of an error in line 14.
E. A ClassCastException is thrown at runtime.

Answer: A
Section: All

Explanation/Reference:

QUESTION 27

Click the Exhibit button.

1. public class Threads1 {
2. int x = 0;
3. public class Runner implements Runnable {
4. public void run(){
5. int current = 0;
6. for(int i = 0; i<4; i++){
7. current = x;
8. System.out.println(current + ", ");
9. x = current + 2;
10. }
11. }
12. }
13.
14. public static void main(String[] args) {
15. new Threads1().go();
16. }
17.
18. public void go(){
19. Runnable r1 = new Runner();
20. new Thread(r1).start();
21. new Thread(r1).start();
22. }
23. }

Which two are possible results? (Choose two.)

A. 0, 2, 4, 4, 6, 8, 10, 6,
B. 0, 2, 4, 6, 8, 10, 2, 4,
C. 0, 2, 4, 6, 8, 10, 12, 14,
D. 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
E. 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

Answer: C
Section: All

Explanation/Reference:

QUESTION 28

Given:
foo and bar are public references available to many other threads. foo refers to a Thread and bar is an
Object.
The thread foo is currently executing bar.wait(). From another thread, what provides the most reliable way
to ensure that foo will stop executing wait()?

A. foo.notify();
B. bar.notify();
C. foo.notifyAll();
D. Thread.notify();
E. bar.notifyAll();
F. Object.notify();

Answer: E
Section: All

Explanation/Reference:

QUESTION 29

Given:
public class PingPong implements Runnable {
     synchronized void hit(long n) {
         for (int i = 1; i < 3; i++)
              System.out.print(n + "-" + i + " ");
     }   
     public static void main(String[] args) {
          new Thread(new PingPong()).start();
          new Thread(new PingPong()).start();
     }
     public void run() {
          hit(Thread.currentThread().getId());
     }
}
Which two statements are true? (Choose two.)

A. The output could be 8-1 7-2 8-2 7-1
B. The output could be 7-1 7-2 8-1 6-1
C. The output could be 8-1 7-1 7-2 8-2
D. The output could be 8-1 8-2 7-1 7-2

Answer: CD
Section: All

Explanation/Reference:

QUESTION 30

Click the Exhibit button.

class Computation extends Thread {
     private int num;
     private boolean isComplete;
     private int result;
     public Computation(int num){ this.num = num; }
     public synchronized void run() {
          result = num * 2;
          isComplete = true;
          notify();
     }   
     public synchronized int getResult() {
          while ( ! isComplete ){
               try {
                   wait();
              } catch (InterruptedException e) {
              }
          }
          return result;
     }   
     public static void main(String[] args) {
          Computation[] computations = new Computation[4];
          for (int i = 0; i < computations.length; i++) {
              computations[i] = new Computation(i);
              computations[i].start();
          }
          for (Computation c : computations) {
              System.out.println(c.getResult() + " ");
          }
     }
}

What is the result?

A. The code will deadlock.
B. The code may run with no output.
C. An exception is thrown at runtime.
D. The code may run with output "0 6".
E. The code may run with output "2 0 6 4".
F. The code may run with output "0 2 4 6".

Answer: F
Section: All

Explanation/Reference:


Wednesday, December 26, 2012

EXAM D


QUESTION 1

Given:
interface Foo { int bar(); }
public class Sprite {
     public int fubar( Foo foo ) { return foo.bar(); }
     public void testFoo() {
          fubar(
            //insert code here 15
          );
     }
}
Which code, inserted at line 15, allows the class Sprite to compile?

A. Foo { public int bar() { return 1; }
B. new Foo { public int bar() { return 1; }
C. new Foo() { public int bar() { return 1; }
D. new class Foo { public int bar() { return 1; }

Answer: C
Section: All

Explanation/Reference:

QUESTION 2

Given:
11. public enum Title {
12. MR("Mr."), MRS("Mrs."), MS("Ms.");
13. private final String title;
14. private Title(String t) { title = t; }
15. public String format(String last, String first) {
16. return title + " " + first + " " + last;
17. }
18. }

     public static void main(String[] args) {
          System.out.println(Title.MR.format("Doe", "John"));
     }
   
What is the result?

A. Mr. John Doe
B. An exception is thrown at runtime.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 20.

Answer: A
Section: All

Explanation/Reference:

QUESTION 3

Given the following six method names:

   addListener
   addMouseListener
   setMouseListener
   deleteMouseListener
   removeMouseListener
   registerMouseListener
 
How many of these method names follow JavaBean Listener naming rules?

A. 1
B. 2
C. 3
D. 4
E. 5

Answer: B
Section: All

Explanation/Reference:

QUESTION 4

Given:
class Line {
     public static class Point {}
}
class Triangle {
     public Triangle(){
        //  insert code here
     }
}
Which code, inserted at line 15, creates an instance of the Point class defined in Line?

A. Point p = new Point();
B. Line.Point p = new Line.Point();
C. The Point class cannot be instatiated at line 15.
D. Line l = new Line() ; l.Point p = new l.Point();

Answer: B
Section: All

Explanation/Reference:

QUESTION 5

Given:
11. public interface Status {
12. /* insert code here */ int MY_VALUE = 10;
13. }
Which three are valid on line 12? (Choose three.)

A. final
B. static
C. native
D. public
E. private
F. abstract
G. protected

Answer: ABD
Section: All

Explanation/Reference:

QUESTION 6

Click the Exhibit button.
Given this code from Class B:

  25. A a1 = new A();
  26. A a2 = new A();
  27. A a3 = new A();
  28. System.out.println(A.getInstanceCount());

What is the result?

1. public class A{
2.
3. private int counter = 0;
4.
5. public static int getInstanceCount() {
6. return counter;
7. }
8.
9. public A() {
10. counter++;
11. }
12.
13. }


A. Compilation of class A fails.
B. Line 28 prints the value 3 to System.out.
C. Line 28 prints the value 1 to System.out.
D. A runtime error occurs when line 25 executes.
E. Compilation fails because of an error on line 28.

Answer: A
Section: All

Explanation/Reference:

QUESTION 7

Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. public static void process(byte[] b) { /* 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
Section: All

Explanation/Reference:

QUESTION 8

Click the Exhibit button.
Which three code fragments, added individually at line 29, produce the output 100? (Choose three.)

class Inner {
     private int x;
     public void setX( int x ){ this.x = x; }
     public int getX(){ return x;}
}

class Outer {
     private Inner y;
     public void setY( Inner y ){ this.y = y; }
     public Inner getY() { return y; }
}

public class Gamma {
     public static void main(String[] args) {
          Outer o = new Outer();
          Inner i = new Inner();
          int n = 10;
          i.setX(n);
          o.setY(i);
          // insert code here 29
          System.out.println(o.getY().getX());
       
     }
}

A. n = 100;
B. i.setX( 100 );
C. o.getY().setX( 100 );
D. i = new Inner(); i.setX( 100 );
E. o.setY( i ); i = new Inner(); i.setX( 100 );
F. i = new Inner(); i.setX( 100 ); o.setY( i );

Answer: BCF
Section: All

Explanation/Reference:

QUESTION 9

Click the Exhibit button.
Given the fully-qualified class names:

   com.foo.bar.Dog
   com.foo.bar.blatz.Book
   com.bar.Car
   com.bar.blatz.Sun
 
Which graph represents the correct directory structure for a JAR file from which those classes can be used
by the compiler and JVM?



A. Jar A
B. Jar B
C. Jar C
D. Jar D
E. Jar E

Answer: A
Section: All

Explanation/Reference:

QUESTION 10

Which statement is true?

A. A class's finalize() method CANNOT be invoked explicitly.
B. super.finalize() is called implicitly by any overriding finalize() method.
C. The finalize() method for a given object is called no more than once by the garbage collector.
D. The order in which finalize() is called on two objects is based on the order in which the two objects  became finalizable.
 
Answer: C
Section: All

Explanation/Reference:

QUESTION 11

Given:
class Snoochy {
     Boochy booch;   
     public Snoochy() { booch = new Boochy(this); }
}
class Boochy {
     Snoochy snooch;
     public Boochy(Snoochy s) { snooch = s; }
}
And the statements:
public static void main(String[] args) {
     Snoochy snoog = new Snoochy();
     snoog = null; //Línea 23
    // more code here
}

Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes?

A. None of these objects are eligible for garbage collection.
B. Only the object referenced by booch is eligible for garbage collection.
C. Only the object referenced by snoog is eligible for garbage collection.
D. Only the object referenced by snooch is eligible for garbage collection.
E. The objects referenced by snooch and booch are eligible for garbage collection.

Answer: E
Section: All

Explanation/Reference:

QUESTION 12

Given:
3. interface Animal { void makeNoise(); }
4. class Horse implements Animal {
5. Long weight = 1200L;
6. public void makeNoise() { System.out.println("whinny"); }
7. }
8. public class Icelandic extends Horse {
9. public void makeNoise() { System.out.println("vinny"); }
10. public static void main(String[] args) {
11. Icelandic i1 = new Icelandic();
12. Icelandic i2 = new Icelandic();
13. Icelandic i3 = new Icelandic();
14. i3 = i1; i1 = i2; i2 = null; i3 = i1;
15. }
16. }   
   
When line 15 is reached, how many objects are eligible for the garbage collector?

A. 0
B. 1
C. 2
D. 3
E. 4
F. 6

Answer: E
Section: All

Explanation/Reference:

QUESTION 13

Given:
class Payload {
     private int weight;
     public Payload (int w) { weight = w; }
     public void setWeight(int w) { weight = w; }
     public String toString() { return Integer.toString(weight); }
}
public class TestPayload {
     static void changePayload(Payload p) { /* insert code */ } //Línea 12
     public static void main(String[] args) {
          Payload p = new Payload(200);
          p.setWeight(1024);
          changePayload(p);
          System.out.println("p is " + p);
     } 
}   
   
Which code fragment, inserted at the end of line 12, produces the output p is 420?

A. p.setWeight(420);
B. p.changePayload(420);
C. p = new Payload(420);
D. Payload.setWeight(420);
E. p = Payload.setWeight(420);

Answer: A
Section: All

Explanation/Reference:

QUESTION 14

Given:
public static void test(String str) {
     int check = 4;
     if (check = str.length()) {
          System.out.print(str.charAt(check -= 1) +", ");
     } else {
          System.out.print(str.charAt(0) + ", ");
     }
}
and the invocation:

test("four");
test("tee");
test("to");

What is the result?

A. r, t, t,
B. r, e, o,
C. Compilation fails.
D. An exception is thrown at runtime.

Answer: C
Section: All

Explanation/Reference:

QUESTION 15

A UNIX user named Bob wants to replace his chess program with a new one, but he is not sure where the old one is installed. Bob is currently able to run a Java chess program starting from his home directory /home/bob using the
command:
     java -classpath /test:/home/bob/downloads/*.jar games.
Chess Bob's CLASSPATH is set (at login time) to:
    /usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/*.jar

What is a possible location for the Chess.class file?

A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct manifest)

Answer: C
Section: All

Explanation/Reference:

QUESTION 16

Given classes defined in two different files:

package util;
public class BitUtils {
     private static void process(byte[] b) {}
}
package app;
public class SomeApp {
     public static void main(String[] args) {
          byte[] bytes = new byte[256];
// insert code here Linea 5
     }
}

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);
E. import util.BitUtils.*; process(bytes);
F. SomeApp cannot use the process method in BitUtils.

Answer: F
Section: All

Explanation/Reference:

QUESTION 17

Given:
public class Pass2 {
     public void main(String [] args) {
          int x = 6;
          Pass2 p = new Pass2();
          p.doStuff(x);
          System.out.print(" main x = " + x);
     }
   
     void doStuff(int x) {
          System.out.print(" doStuff x = " + x++);
     }
}

And the command-line invocations:
  javac Pass2.java
  java Pass2 5

What is the result?

A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuff x = 6 main x = 6
D. doStuff x = 6 main x = 7
E. doStuff x = 7 main x = 6
F. doStuff x = 7 main x = 7

Answer: B
Section: All

Explanation/Reference:

QUESTION 18

Given:
public class Test {
     public enum Dogs {collie, harrier};
     public static void main(String [] args) {
          Dogs myDog = Dogs.collie;
          switch (myDog) {
          case collie:
              System.out.print("collie ");
          case harrier:
              System.out.print("harrier ");
          }
     }
}

What is the result?

A. collie
B. harrier
C. Compilation fails.
D. collie harrier
E. An exception is thrown at runtime.

Answer: D
Section: All

Explanation/Reference:

QUESTION 19

Given:
public class Donkey {
     public static void main(String[] args) {
          boolean assertsOn = false;
          assert (assertsOn) : assertsOn = true;
          if(assertsOn) {
              System.out.println("assert is on");
          }
     }
}
If class Donkey is invoked twice, the first time without assertions enabled, and the second time with
assertions enabled, what are the results?

A. no output
B. no output  assert is on
C. assert is on
D. no output  An AssertionError is thrown.
E. assert is on  An AssertionError is thrown.
 
Answer: D
Section: All

Explanation/Reference:

QUESTION 20

Given:
static void test() {
     try {
          String x = null;
          System.out.print(x.toString() + " ");
     }
     finally { System.out.print("finally "); }
}
public static void main(String[] args) {
     try { test(); }
     catch (Exception ex) { System.out.print("exception "); }
}
What is the result?

A. null
B. finally
C. null finally
D. Compilation fails.
E. finally exception

Answer: E
Section: All

Explanation/Reference:

QUESTION 21

Given:
static void test() throws Error {
     if (true) throw new AssertionError();
     System.out.print("test ");
}
public static void main(String[] args) {
     try { test(); }
     catch (Exception ex) { System.out.print("exception "); }
     System.out.print("end ");
}}
What is the result?

A. end
B. Compilation fails.
C. exception end
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.

Answer: E
Section: All

Explanation/Reference:

QUESTION 22

Given:
class TestException extends Exception { }
class A {
     public String sayHello(String name) throws TestException {
          if(name == null) throw new TestException();
          return "Hello " + name;
     }
}
public class TestA {
     public static void main(String[] args) {
          new A().sayHello("Aiko");
     }
}

Which statement is true?

A. Compilation succeeds.
B. Class A does not compile.
C. The method declared on line 9 cannot be modified to throw TestException.
D. TestA compiles if line 10 is enclosed in a try/catch block that catches TestException.

Answer: D
Section: All

Explanation/Reference:


QUESTION 23

Given:
public static Collection get() {
     Collection sorted = new LinkedList();
     sorted.add("B"); sorted.add("C"); sorted.add("A");
     return sorted;
}
public static void main(String[] args) {
     for (Object obj: get()) {
          System.out.print(obj + ", ");
     }
}

What is the result?

A. A, B, C,
B. B, C, A,
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.

Answer: B
Section: All

Explanation/Reference:

QUESTION 24

Given:
static class A {
     void process() throws Exception { throw new Exception(); }
}
static class B extends A {
     void process() { System.out.println("B"); }
}
public static void main(String[] args) {
     new B().process();
}
What is the result?

A. B
B. The code runs with no output.
C. Compilation fails because of an error in line 12.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.

Answer: A
Section: All

Explanation/Reference:

QUESTION 25

Given:
public class Foo {
     static int[] a;
     static { a[0]=2; }
     public static void main( String[] args ) {}
}
Which exception or error will be thrown when a programmer attempts to run this code?

A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitializerError
D. java.lang.ArrayIndexOutOfBoundsException

Answer: C
Section: All

Explanation/Reference:

QUESTION 26

Click the Exhibit button.
Given: ClassA a = new ClassA();
a.methodA();


What is the result?

A. Compilation fails.
B. ClassC is displayed.
C. The code runs with no output.
D. An exception is thrown at runtime.

Answer: D
Section: All

Explanation/Reference:

QUESTION 27

Given:
public static void main(String[] args) {
     Integer i = new Integer(1) + new Integer(2);
     switch(i) {
     case 3: System.out.println("three"); break;
     default: System.out.println("other"); break;
     }
}

What is the result?

A. three
B. other
C. An exception is thrown at runtime.
D. Compilation fails because of an error on line 12.
E. Compilation fails because of an error on line 13.
F. Compilation fails because of an error on line 15.

Answer: A
Section: All

Explanation/Reference:

QUESTION 28

Given:
public static Iterator reverse(List list) {
     Collections.reverse(list);
     return list.iterator();
}
public static void main(String[] args) {
     List list = new ArrayList();
     list.add("1"); list.add("2"); list.add("3");
     for (Object obj: reverse(list))
          System.out.print(obj + ", ");
}

What is the result?

A. 3, 2, 1,
B. 1, 2, 3,
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.

Answer: C
Section: All

Explanation/Reference:

QUESTION 29

Given:

1. public class TestString3 {
2. public static void main(String[] args) {
3. // insert code here
4.
5. System.out.println(s);
6. }
7. }

Which two code fragments, inserted independently at line 3, generate the output 4247? (Choose two.)

A. String s = "123456789";  s = (s-"123").replace(1,3,"24") - "89";
B. StringBuffer s = new StringBuffer("123456789");
C. s.delete(0,3).replace(1,3,"24").delete(4,6);
D. StringBuffer s = new StringBuffer("123456789");
E. substring(3,6).delete(1,3).insert(1, "24");
F. StringBuilder s = new StringBuilder("123456789");
G. substring(3,6).delete(1,2).insert(1, "24");
H. StringBuilder s = new StringBuilder("123456789");
I.  delete(0,3).delete(1,3).delete(2,5).insert(1, "24");

Answer: BC
Section: All

Explanation/Reference:

QUESTION 30

Given:

1. d is a valid, non-null Date object
2. df is a valid, non-null DateFormat object set to the current locale

What outputs the current locale's country name and the appropriate version of d's date?

A. Locale loc = Locale.getLocale();
   System.out.println(loc.getDisplayCountry() + " " + df.format(d));
B. Locale loc = Locale.getDefault();
   System.out.println(loc.getDisplayCountry() + " " + df.format(d));
C. Locale loc = Locale.getLocale();
   System.out.println(loc.getDisplayCountry() + " " + df.setDateFormat(d));
D. Locale loc = Locale.getDefault();
   System.out.println(loc.getDisplayCountry() + " " + df.setDateFormat(d));

Answer: B
Section: All

Explanation/Reference:

QUESTION 31

Click the Exhibit button.
What is the output if the main() method is run?

1. public class Starter extends Thread {
2. private int x = 2;
3. public static void main(String[] args) throws Exception {
4. new Starter().makeItSo();
5. }
6. public Starter(){
7. x = 5;
8. start();
9. }
10. public void makeItSo() throws Exception {
11. join();
12. x = x - 1;
13. System.out.println(x);
14. }
15. public void run() { x *= 2; }
16. }

A. 4
B. 5
C. 8
D. 9
E. Compilation fails.
F. An exception is thrown at runtime.
G. It is impossible to determine for certain.

Answer: D
Section: All

Explanation/Reference:

QUESTION 32

Given:

21. class Money {
22. private String country = "Canada";
23. public String getC() { return country; }
24. }
25. class Yen extends Money {
26. public String getC() { return super.country; }
27. }
28. public class Euro extends Money {
29. public String getC(int x) { return super.getC(); }
30. public static void main(String[] args) {
31. System.out.print(new Yen().getC() + " " + new Euro().getC());
32. }
33. }

What is the result?

A. Canada
B. null Canada
C. Canada null
D. Canada Canada
E. Compilation fails due to an error on line 26.
F. Compilation fails due to an error on line 29.

Answer: E
Section: All

Explanation/Reference:
The field Money.country is not visible

Tuesday, December 25, 2012

EXAM C


QUESTION 1

A company has a business application that provides its users with many different reports:
receivables reports, payables reports, revenue projects, and so on. The company has just purchased some new, state-of-the-art, wireless printers, and a programmer has been assigned the task of enhancing all of the reports to use not only the company's old printers, but the new wireless printers as well. When the programmer starts looking into the application, the programmer discovers that because of the design of the application, it is necessary to make changes to each report to support the new printers.Which two design concepts most likely explain this situation? (Choose two.)

A. Inheritance
B. Low cohesion
C. Tight coupling
D. High cohesion
E. Loose coupling
F. Object immutability

Answer: BC
Section: All

Explanation/Reference:

QUESTION 2

Given:
10. public class SuperCalc {
11. protected static int multiply(int a, int b) { return a * b;}
12. }
and:
20. public class SubCalc extends SuperCalc{
21. public static int multiply(int a, int b) {
22. int c = super.multiply(a, b);
23. return c;
24. }
25. }
and:
30. SubCalc sc = new SubCalc ();
31. System.out.println(sc.multiply(3,4));
32. System.out.println(SubCalc.multiply(2,2));

What is the result?

A. 12
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 21.
E. Compilation fails because of an error in line 22.
F. Compilation fails because of an error in line 31.

Answer: E
Section: All

Explanation/Reference:

QUESTION 3

Given:
class Foo {
     public int a = 3;
     public void addFive() { a += 5; System.out.print("f "); }
}
class Bar extends Foo {
     public int a = 8;
     public void addFive() { this.a += 5; System.out.print("b " ); }
}
Invoked with:

Foo f = new Bar();
f.addFive();
System.out.println(f.a);

What is the result?

A. b3
B. b8
C. b 13
D. f3
E. f8
F. f 13
G. Compilation fails.
H. An exception is thrown at runtime.

Answer: A
Section: All

Explanation/Reference:

QUESTION 4

A company that makes Computer Assisted Design (CAD) software has, within its application, some utility classes that are used to perform 3D rendering tasks. The company's chief scientist has just improved the performance of one of the utility classes' key rendering algorithms, and has assigned a programmer to replace the old algorithm with the new algorithm. When the programmer begins researching the utility classes, she is happy to discover that the algorithm to be replaced exists in only one class. The programmer reviews that class's API, and replaces the old algorithm with the new algorithm, being careful that her changes adhere strictly to the class's API. Once testing has begun, the programmer discovers that other classes that use the class she changed are no longer working properly. What design flaw is most likely the cause of these new bugs?

A. Inheritance
B. Tight coupling
C. Low cohesion
D. High cohesion
E. Loose coupling
F. Object immutability

Answer: B
Section: All

Explanation/Reference:

QUESTION 5

Given:
1. class ClassA {
2. public int numberOfInstances;
3. protected ClassA(int numberOfInstances) {
4. this.numberOfInstances = numberOfInstances;
5. }
6. }
7. public class ExtendedA extends ClassA {
8. private ExtendedA(int numberOfInstances) {
9. super(numberOfInstances);
10. }
11. public static void main(String[] args) {
12. ExtendedA ext = new ExtendedA(420);
13. System.out.print(ext.numberOfInstances);
14. }
15. }
Which statement is true?

A. 420 is the output.
B. An exception is thrown at runtime.
C. All constructors must be declared public.
D. Constructors CANNOT use the private modifier.
E. Constructors CANNOT use the protected modifier.

Answer: A
Section: All

Explanation/Reference:

QUESTION 6

Given:
class ClassA {}
class ClassB extends ClassA {}
class ClassC extends ClassA {}
and:
ClassA p0 = new ClassA();
ClassB p1 = new ClassB();
ClassC p2 = new ClassC();
ClassA p3 = new ClassB();
ClassA p4 = new ClassC();

Which three are valid? (Choose three.)

A. p0 = p1;
B. p1 = p2;
C. p2 = p4;
D. p2 = (ClassC)p1;
E. p1 = (ClassB)p3;
F. p2 = (ClassC)p4;

Answer: AEF
Section: All

Explanation/Reference:

QUESTION 7

Given:
class Thingy { Meter m = new Meter(); }
class Component { void go() { System.out.print("c"); } }
class Meter extends Component { void go() { System.out.print("m"); } } 8.
class DeluxeThingy extends Thingy {
     public static void main(String[] args) {
          DeluxeThingy dt = new DeluxeThingy();
          dt.m.go();
          Thingy t = new DeluxeThingy();
          t.m.go();
     }
}
Which two are true? (Choose two.)

A. The output is mm.
B. The output is mc.
C. Component is-a Meter.
D. Component has-a Meter.
E. DeluxeThingy is-a Component.
F. DeluxeThingy has-a Component.

Answer: AF
Section: All

Explanation/Reference:

QUESTION 8

Given:
10. interface Jumper { public void jump(); }
...
20. class Animal {}
...
30. class Dog extends Animal {
31. Tail tail;
32. }
...
40. class Beagle extends Dog implements Jumper{
41. public void jump() {}
42. }
...
50. class Cat implements Jumper{
51. public void jump() {}
52. }
Which three are true? (Choose three.)

A. Cat is-a Animal
B. Cat is-a Jumper
C. Dog is-a Animal
D. Dog is-a Jumper
E. Cat has-a Animal
F. Beagle has-a Tail
G. Beagle has-a Jumper

Answer: BCF
Section: All

Explanation/Reference:

QUESTION 9

Given:
1. import java.util.*;
2. public class WrappedString {
3. private String s;
4. public WrappedString(String s) { this.s = s; }
5. public static void main(String[] args) {
6. HashSet<Object> hs = new HashSet<Object>();
7. WrappedString ws1 = new WrappedString("aardvark");
8. WrappedString ws2 = new WrappedString("aardvark");
9. String s1 = new String("aardvark");
10. String s2 = new String("aardvark");
11. hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);
12. System.out.println(hs.size()); } }

What is the result?

A. 0
B. 1
C. 2
D. 3
E. 4
F. Compilation fails.
G. An exception is thrown at runtime.

Answer: D
Section: All

Explanation/Reference:

QUESTION 10

Given:
11. //insert code here
     private N min, max;
     public N getMin() { return min; }
     public N getMax() { return max; }
     public void add(N added) {
          if (min == null || added.doubleValue() < min.doubleValue())
              min = added;
          if (max == null || added.doubleValue() > max.doubleValue())
              max = added;
     }
}
Which two, inserted at line 11, will allow the code to compile? (Choose two.)

A. public class MinMax<?> {
B. public class MinMax<? extends Number> {
C. public class MinMax<N extends Object> {
D. public class MinMax<N extends Number> {
E. public class MinMax<? extends Object> {
F. public class MinMax<N extends Integer> {

Answer: DF
Section: All

Explanation/Reference:

QUESTION 11

Given:
3. import java.util.*;
4. public class G1 {
5. public void takeList(List<? extends String> list) {
6. // insert code here
7. }
8. }
Which three code fragments, inserted independently at line 6, will compile? (Choose three.)

A. list.add("foo");
B. Object o = list;
C. String s = list.get(0);
D. list = new ArrayList<String>();
E. list = new ArrayList<Object>();

Answer: BCD
Section: All

Explanation/Reference:

QUESTION 12

Given that the elements of a PriorityQueue are ordered according to natural ordering, and:
import java.util.*;
public class GetInLine {
     public static void main(String[] args) {
          PriorityQueue<String> pq = new PriorityQueue<String>();
          pq.add("banana");
          pq.add("pear");
          pq.add("apple");
          System.out.println(pq.poll() + " " + pq.peek());
     }
}
What is the result?

A. apple pear
B. banana pear
C. apple apple
D. apple banana
E. banana banana

Answer: D
Section: All

Explanation/Reference:

QUESTION 13

Given:
enum Example { ONE, TWO, THREE }
Which statement is true?

A. The expressions (ONE == ONE) and ONE.equals(ONE) are both guaranteed to be true.
B. The expression (ONE < TWO) is guaranteed to be true and ONE.compareTo(TWO) is guaranteed to be  less than one.
C. The Example values cannot be used in a raw java.util.HashMap; instead, the programmer must use a  java.util.EnumMap.
D. The Example values can be used in a java.util.SortedSet, but the set will NOT be sorted because    enumerated types do NOT implement java.lang.Comparable.
 
Answer: A
Section: All

Explanation/Reference:

QUESTION 14

Given:
import java.util.*;
public class Mapit {
     public static void main(String[] args) {
          Set<Integer> set = new HashSet<Integer>();
          Integer i1 = 45;
          Integer i2 = 46;
          set.add(i1);
          set.add(i1);
          set.add(i2); System.out.print(set.size() + " ");
          set.remove(i1); System.out.print(set.size() + " ");
          i2 = 47;
          set.remove(i2); System.out.print(set.size() + " ");
     }
}
What is the result?

A. 210
B. 211
C. 321
D. 322
E. Compilation fails.
F. An exception is thrown at runtime.

Answer: B
Section: All

Explanation/Reference:

QUESTION 15

Given:
import java.util.*;
public class Explorer1 {
     public static void main(String[] args) {
          TreeSet<Integer> s = new TreeSet<Integer>();
          TreeSet<Integer> subs = new TreeSet<Integer>();
          for(int i = 606; i < 613; i++)
               if(i%2 == 0) s.add(i);
          subs = (TreeSet)s.subSet(608, true, 611, true);
          s.add(609);
          System.out.println(s + " " + subs);
     }
}

What is the result?

A. Compilation fails.
B. An exception is thrown at runtime.
C. [608, 609, 610, 612] [608, 610]
D. [608, 609, 610, 612] [608, 609, 610]
E. [606, 608, 609, 610, 612] [608, 610]
F. [606, 608, 609, 610, 612] [608, 609, 610]

Answer: F
Section: All

Explanation/Reference:

QUESTION 16

Given:
import java.util.*;
public class Quest {
     public static void main(String[] args) {
          String[] colors = {"blue", "red", "green", "yellow", "orange"};
          Arrays.sort(colors);
          int s2 = Arrays.binarySearch(colors, "orange");
          int s3 = Arrays.binarySearch(colors, "violet");
          System.out.println(s2 + " " + s3);
     }
}
What is the result?

A. 2 -1
B. 2 -4
C. 2 -5
D. 3 -1
E. 3 -4
F. 3 -5
G. Compilation fails.
H. An exception is thrown at runtime.

Answer: C
Section: All

Explanation/Reference:

QUESTION 17

Given:
HashMap props = new HashMap();
props.put("key45", "some value");
props.put("key12", "some other value");
props.put("key39", "yet another value");
Set s = props.keySet();
//insert code here
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
Section: All

Explanation/Reference:

QUESTION 18

Which two statements are true? (Choose two.)

A. It is possible to synchronize static methods.
B. When a thread has yielded as a result of yield(), it releases its locks.
C. When a thread is sleeping as a result of sleep(), it releases its locks.
D. The Object.wait() method can be invoked only from a synchronized context.
E. The Thread.sleep() method can be invoked only from a synchronized context.
F. When the thread scheduler receives a notify() request, and notifies a thread, that thread immediately releases its lock.
 
Answer: AD
Section: All

Explanation/Reference:

QUESTION 19

Given:
public class TestOne implements Runnable {
     public static void main (String[] args) throws Exception {
          Thread t = new Thread(new TestOne());
          t.start();
          System.out.print("Started");
          t.join();
          System.out.print("Complete");
     }
     public void run() {
          for (int i = 0; i < 4; i++) {
              System.out.print(i);
          }
     }
}
What can be a result?

A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes and prints "StartedComplete".
D. The code executes and prints "StartedComplete0123".
E. The code executes and prints "Started0123Complete".

Answer: E
Section: All

Explanation/Reference:

QUESTION 20

Which three will compile and run without exception? (Choose three.)

A. private synchronized Object o;
B. void go() {
   synchronized() { /* code here */ }
C. public synchronized void go() { /* code here */ }
D. private synchronized(this) void go() { /* code here */ }
E. void go() {
   synchronized(Object.class) { /* code here */ }
F. void go() {
   Object o = new Object();
   synchronized(o) { /* code here */ }
 
Answer: CEF
Section: All

Explanation/Reference:

QUESTION 21

Given:
1. public class TestFive {
2. private int x;
3. public void foo() {
4. int current = x;
5. x = current + 1;
6. }
7. public void go() {
8. for(int i = 0; i < 5; i++) {
9. new Thread() {
10. public void run() {
11. foo();
12. System.out.print(x + ", ");
13. } }.start();
14. } }
15. }

Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ? (Choose two.)

A. move the line 12 print statement into the foo() method
B. change line 7 to public synchronized void go() {
C. change the variable declaration on line 2 to private volatile int x;
D. wrap the code inside the foo() method with a synchronized( this ) block
E. wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop
   code here }
 
Answer: AD
Section: All

Explanation/Reference:

QUESTION 22

Given that t1 is a reference to a live thread, which is true?

A. The Thread.sleep() method can take t1 as an argument.
B. The Object.notify() method can take t1 as an argument.
C. The Thread.yield() method can take t1 as an argument.
D. The Thread.setPriority() method can take t1 as an argument.
E. The Object.notify() method arbitrarily chooses which thread to notify.

Answer: E
Section: All

Explanation/Reference:

QUESTION 23

Given:
Runnable r = new Runnable() {
     public void run() {
          System.out.print("Cat");
     }
};
Thread t = new Thread(r) {
     public void run() {
          System.out.print("Dog");
     }
};
t.start();
What is the result?

A. Cat
B. Dog
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.

Answer: B
Section: All

Explanation/Reference:

QUESTION 24

Given:
1. public class Threads5 {
2. public static void main (String[] args) {
3. new Thread(new Runnable() {
4. public void run() {
5. System.out.print("bar");
6. }}).start();
7. }
8. }

What is the result?

A. Compilation fails.
B. An exception is thrown at runtime.
C. The code executes normally and prints "bar".
D. The code executes normally, but nothing prints.

Answer: C
Section: All

Explanation/Reference:

QUESTION 25

Given:
class One {
     void foo() { }
}
class Two extends One {
14. // insert method here
}

Which three methods, inserted individually at line 14, will correctly complete class Two? (Choose three.)

A. int foo() { /* more code here */ }
B. void foo() { /* more code here */ }
C. public void foo() { /* more code here */ }
D. private void foo() { /* more code here */ }
E. protected void foo() { /* more code here */ }

Answer: BCE
Section: All

Explanation/Reference:

QUESTION 26

Given:
abstract public class Employee {
     protected abstract double getSalesAmount();
     public double getCommision() {
          return getSalesAmount() * 0.15;
     }
}
class Sales extends Employee {
17. // insert method here
}

Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.)

A. double getSalesAmount() { return 1230.45; }
B. public double getSalesAmount() { return 1230.45; }
C. private double getSalesAmount() { return 1230.45; }
D. protected double getSalesAmount() { return 1230.45; }

Answer: BD
Section: All

Explanation/Reference:

QUESTION 27

Given:
1. class X {
2. X() { System.out.print(1); }
3. X(int x) {
4. this(); System.out.print(2);
5. }
6. }
7. public class Y extends X {
8. Y() { super(6); System.out.print(3); }
9. Y(int y) {
10. this(); System.out.println(4);
11. }
12. public static void main(String[] a) { new Y(5); }
13. }
What is the result?

A. 13
B. 134
C. 1234
D. 2134
E. 2143
F. 4321

Answer: C
Section: All

Explanation/Reference:

QUESTION 28

Given:
package com.sun.scjp;
public class Geodetics {
     public static final double DIAMETER = 12756.32; // kilometers
}
Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.)

A. import com.sun.scjp.Geodetics;
   public class TerraCarta {
        public double halfway()
        { return Geodetics.DIAMETER/2.0; }
B. import static com.sun.scjp.Geodetics;
   public class TerraCarta{
   public double halfway() { return DIAMETER/2.0; } }
C. import static com.sun.scjp.Geodetics.*;
   public class TerraCarta {
        public double halfway() { return DIAMETER/2.0; } }
D. package com.sun.scjp;
   public class TerraCarta {
        public double halfway() { return DIAMETER/2.0; } }
     
Answer: AC
Section: All

Explanation/Reference:

QUESTION 29

Given:
1. public class A {
2. public void doit() {
3. }
4. public String doit() {
5. return "a";
6. }
7. public double doit(int x) {
8. return 1.0;
9. }
10. }
What is the result?

A. An exception is thrown at runtime.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 4.
D. Compilation succeeds and no runtime errors with class A occur.

Answer: C
Section: All

Explanation/Reference:

QUESTION 30

Given:
35. String #name = "Jane Doe";
36. int $age = 24;
37. Double _height = 123.5;
38. double ~temp = 37.5;

Which two statements are true? (Choose two.)

A. Line 35 will not compile.
B. Line 36 will not compile.
C. Line 37 will not compile.
D. Line 38 will not compile.

Answer: AD
Section: All

Explanation/Reference:

QUESTION 31

Click the Exhibit button.
Given the fully-qualified class names:

   com.foo.bar.Dog
   com.foo.bar.blatz.Book
   com.bar.Car
   com.bar.blatz.Sun
 
Which graph represents the correct directory structure for a JAR file from which those classes can be used by the compiler and JVM?




A. Jar A
B. Jar B
C. Jar C
D. Jar D
E. Jar E

Answer: A
Section: All

Explanation/Reference:

QUESTION 32

Click the Exhibit button.
Given: ClassA a = new ClassA();
a.methodA();


What is the result?

A. Compilation fails.
B. ClassC is displayed.
C. The code runs with no output.
D. An exception is thrown at runtime.

Answer: D
Section: All

Explanation/Reference: