SCJP / OCJP dumps 1 - Exam E




You are here : Home / Core Java Tutorials /  SCJP / OCJP dumps

Sun.RealExamQuestions.310-065.Oracle.1Z0-851.v2012-01-28.by.Carlos.239q
Number: 1Z0-851 Passing Score: 610 Time Limit: 150 min File Version: 2012-01-28
Sun.RealExamQuestions.310-065.Oracle.1Z0-851.v2012-01-28.by.Carlos.239q
Exam : Sun 310-065 / Oracle 1Z0-851
Version : 2012-01-28
By Carlos - Brazil
Questions : 239 9 Exams (from A - I)
This file is based on Sun RealExamQuestions 310-065 v2011-11-08 by Stephen 306q.vce (http:// www.examcollection.com/sun/Sun.RealExamQuestions.310-065.v2011-11-08.by.Stephen.306q.vce. file.html). See the comments on its page for more infos.
Changes made from original file: - Removed duplicated questions. - Many answers were tested and better explained. - Removed "Exam J" because it had only drag and drop questions and other questions that had drag and drop (see posts from "Certification Forum Moderator - Brandye Barrington" on https:// forums.oracle.com/forums/thread.jspa?messageID=9640688&tstart=0#9640688)
----------------


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();
Correct Answer: E 

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.
Correct Answer: B 
Explanation/Reference:
Tested and confirmed.


QUESTION 3 Given:
import java.io.*;

public class Forest implements Serializable {
    private Tree treenew Tree();

    public static void main(String[] args) {
          Forest fnew Forest();
          try {
                 FileOutputStream fsnew FileOutputStream("Forest.ser");
                 ObjectOutputStream osnew 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.
Correct Answer: B 
Explanation/Reference:
Tested and it throws the following exception at run-time: "java.io.NotSerializableException: Tree" on the command "os.writeObject(f);"

QUESTION 4 Given:
1. import java.io.*; 
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.
Correct Answer: E 
Explanation/Reference:
Tested and the compilation really fails on line 8 with the message "The constructor Console() is not visible"

QUESTION 5 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[ \.] +";
Correct Answer: E 

QUESTION 6 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.
Correct Answer: F 

QUESTION 7 Click the Exhibit button. What is the result?
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.
Correct Answer: A 

QUESTION 8 Given:
public class Base {
    public static final String FOO"foo";

    public static void main(String[] args) {
          Base bnew Base();
          Sub snew 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
Correct Answer: D 

QUESTION 9 Given:
1. class Mammal { 
2. } 
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.
Correct Answer: ABCF 

QUESTION 10 Given:

interface A {
    void x();
}

classimplements A {
    public void x() {
    }

    public void y() {
    }
}

classextends 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.
Correct Answer: F 

QUESTION 11 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() { }
Correct Answer: ABEF 

QUESTION 12 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.
Correct Answer: CDEG 

QUESTION 13 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.
Correct Answer: C 
Explanation/Reference:
on the last line, c.title isn't accessible

QUESTION 14 Given: 
1. package geometry; 
3. public class Hypotenuse { 
4. public InnerTriangle it = new InnerTriangle(); 
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.
Correct Answer: C 

QUESTION 15 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*/ } }
Correct Answer: A 

QUESTION 16 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.
Correct Answer: E 

QUESTION 17 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.
Correct Answer: D 
Explanation/Reference:
All constructors are executed in order top (C1) to bottom (C3)

QUESTION 18 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; }
Correct Answer: CD 

 QUESTION 19 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 */ }
Correct Answer: CD 

QUESTION 20 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.
Correct Answer: C 
Explanation/Reference:
class B does NOT compile because it gives the error "The type B must implement the inherited abstract method A.m1()" class D does NOT compile because it gives the error "The type B must implement the inherited abstract
method A.m1()"
classes E and G does not need to implement the inherited abstract method A.m1() because these classes (E and G) are abstract

QUESTION 21 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();
Correct Answer: D 

QUESTION 22 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.
Correct Answer: B


QUESTION 23 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. 1 2 3 
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.
Correct Answer: A 

QUESTION 24 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. } 

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,
Correct Answer: C 
Explanation/Reference:
the first thread prints 0, 2, 4, 6. the second thread executes right after the first one and prints 8, 10, 12, 14

QUESTION 25 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();
Correct Answer: E 

QUESTION 26 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
Correct Answer: CD 

QUESTION 27 Click the Exhibit button.

class Computation extends Thread {
    private int num;
    private boolean isComplete;
    private int result;

    public Computation(int num) {
          this.numnum;
    }

    public synchronized void run() {
          resultnum * 2;
          isCompletetrue;
          notify();
    }

    public synchronized int getResult() {
          while (!isComplete) {
                 try {
                       wait();
                 catch (InterruptedException e) {
                 }
          }
          return result;
    }

    public static void main(String[] args) {
          Computation[] computationsnew Computation[4];
          for (int i = 0; icomputations.lengthi++) {
                 computations[i] = new Computation(i);
                 computations[i].start();
          }
          for (Computation ccomputations) {
                 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".
Correct Answer: F 


QUESTION 28 Given:
1. class Mammal { 
2. } 

4. class Raccoon extends Mammal { 
5. Mammal m = new Mammal(); 
6. } 

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.
Correct Answer: ABCF 


Must read for you :