SCJP / OCJP dumps 1 - Exam F




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 F
QUESTION 1 Which two code fragments will execute the method doStuff() in a separate thread? (Choose two.)
A. new Thread() {
public void run() { doStuff(); } }; 
B. new Thread() {
public void start() { doStuff(); } }; 
C. new Thread() {
public void start() { doStuff(); } }.run(); 
D. new Thread() {
public void run() { doStuff(); } }.start(); 
E. new Thread(new Runnable() {
public void run() { doStuff(); } }).run(); 
F. new Thread(new Runnable() {
public void run() { doStuff(); } }).start();
Correct Answer: DF 

QUESTION 2 Given:
public class Person {
    private String name;

    public Person(String name) {
          this.namename;
    }

    public boolean equals(Object o) {
          if (!(o instanceof Person))
                 return false;
          Person p = (Person) o;
          return p.name.equals(this.name);
    }
}

Which statement is true?
A. Compilation fails because the hashCode method is not overridden. 
B. A HashSet could contain multiple Person objects with the same name. 
C. All Person objects will have the same hash code because the hashCode method is not overridden. 
D. If a HashSet contains more than one Person object with name="Fred", then removing another Person,
also with name="Fred", will remove them all.
Correct Answer: B 

QUESTION 3 Given:

import java.util.*;

public class SortOf {
    public static void main(String[] args) {
          ArrayList<Integer> anew ArrayList<Integer>();
        a.add(1);
          a.add(5);
          a.add(3);
          Collections.sort(a);
          a.add(2);
          Collections.reverse(a);
          System.out.println(a);
    }
}

What is the result?
A. [1, 2, 3, 5] 
B. [2, 1, 3, 5] 
C. [2, 5, 3, 1] 
D. [5, 3, 2, 1] E. [1, 3, 5, 2] 
F. Compilation fails. 
G. An exception is thrown at runtime.
Correct Answer: C 

QUESTION 4 Given: 
public class Person {
    private name;
    public Person(String name) {
    this.name = name;
    }
   
    public int hashCode() {
          return 420;
    }
}

Which statement is true?
A. The time to find the value from HashMap with a Person key depends on the size of the map. 
B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person. 
C. Inserting a second Person object into a HashSet will cause the first Person object to be removed as a
duplicate. 
D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT
depend on the size of the map.
Correct Answer: A 

QUESTION 5 Given:
 import java.util.TreeSet;

public class Explorer2 {
    public static void main(String[] args) {
          TreeSet<Integer> snew TreeSet<Integer>();
          TreeSet<Integer> subsnew 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(629);
          System.out.println(s" "subs);
    }
}


What is the result?
A. Compilation fails. B. An exception is thrown at runtime. 
C. [608, 610, 612, 629] [608, 610] 
D. [608, 610, 612, 629] [608, 610, 629] 
E. [606, 608, 610, 612, 629] [608, 610] 
F. [606, 608, 610, 612, 629] [608, 610, 629]
Correct Answer: E 

QUESTION 6 Given:

public class Drink implements Comparable {
    public String name;

    public int compareTo(Object o) {
          return 0;
    }
}


and:
Drink one = new Drink(); 
Drink two = new Drink(); 
one.name= "Coffee"; 
two.name= "Tea"; 
TreeSet set = new TreeSet(); 
set.add(one); 
set.add(two);
A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?
A. Tea
B. Coffee 
C. Coffee Tea 
D. Compilation fails. 
E. The code runs with no output. 
F. An exception is thrown at runtime.
Correct Answer: B


QUESTION 7 A programmer must create a generic class MinMax and the type parameter of MinMax must implement Comparable. Which implementation of MinMax will compile?
A. class MinMax<E extends Comparable<E>> {
E min = null; E max = null; 
public MinMax() {} 
public void put(E value) { /* store min or max */ } 

B. class MinMax<E implements Comparable<E>> {
E min = null; E max = null; 
public MinMax() {} 
public void put(E value) { /* store min or max */ } 

C. class MinMax<E extends Comparable<E>> {
<E> E min = null; <E> E max = null; 
public MinMax() {} 
public <E> void put(E value) { /* store min or max */ } 

D. class MinMax<E implements Comparable<E>> {
<E> E min = null; <E> E max = null; 
public MinMax() {} 
public <E> void put(E value) { /* store min or max */ }
Correct Answer: A 

QUESTION 8 Given: 
1. import java.util.*; 
2. public class Example { 
3. public static void main(String[] args) { 
4. // insert code here 
5. set.add(new Integer(2)); 
6. set.add(new Integer(1)); 
7. System.out.println(set); 
8. } 
9. } Which code, inserted at line 4, guarantees that this program will output [1, 2]?
A. Set set = new TreeSet(); 
B. Set set = new HashSet(); 
C. Set set = new SortedSet(); 
D. List set = new SortedList(); 
E. Set set = new LinkedHashSet();
Correct Answer: AB 

QUESTION 9 Given: 
5. class A { 
6. void foo() throws Exception { throw new Exception(); } 
7. } 
8. class SubB2 extends A { 
9. void foo() { System.out.println("B "); } 
10.} 
11.class Tester { 
12. public static void main(String[] args) { 
13. A a = new SubB2(); 
14. a.foo(); 
15. } 
16.} 
What is the result?
A. B 
B. B, followed by an Exception. 
C. Compilation fails due to an error on line 9. 
D. Compilation fails due to an error on line 14. 
E. An Exception is thrown with no other output.
Correct Answer: D 
Explanation/Reference:
error "Unhandled exception type Exception" on line 14

QUESTION 10 Given: try {
ResourceConnection con = resourceFactory.getConnection(); 
Results r = con.query("GET INFO FROM CUSTOMER"); // Linea 86 
info = r.getData(); 88. 
con.close(); 
} catch (ResourceException re) {
errorLog.write(re.getMessage());
return info; 

Which statement is true if a ResourceException is thrown on line 86?
A. Line 92 will not execute.
B. The connection will not be retrieved in line 85. 
C. The resource connection will not be closed on line 88. 
D. The enclosing method will throw an exception to its caller.
Correct Answer: C 

QUESTION 11 Given:
public class Breaker {
    static String o"";

    public static void main(String[] args) {
          z: oo + 2;
          for (int x = 3; x < 8; x++) {
                 if (x == 4)
                       break;
                 if (x == 6)
                       break z;
                 oox;
          }
          System.out.println(o);
    }
}


What is the result?
A. 23 
B. 234 
C. 235 
D. 2345 
E. 2357 
F. 23457 
G. Compilation fails.
Correct Answer: G 
Explanation/Reference:
The label z: should be right before the for to compile. And if it executes the output would be 23

QUESTION 12 Given:
public void go(int x) {
assert (x > 0); //Line 12 switch(x) { case 2: ; default: assert false; //Line 15 } } private void go2(int x) { assert (x < 0); } //Line 18

Which statement is true?
A. All of the assert statements are used appropriately. 
B. Only the assert statement on line 12 is used appropriately. 
C. Only the assert statement on line 15 is used appropriately.
D. Only the assert statement on line 18 is used appropriately. 
E. Only the assert statements on lines 12 and 15 are used appropriately. 
F. Only the assert statements on lines 12 and 18 are used appropriately. 
G. Only the assert statements on lines 15 and 18 are used appropriately.
Correct Answer: G 

QUESTION 13 Given:

    public static void main(String[] args) {
          try {
                 argsnull;
                 args[0] = "test";
                 System.out.println(args[0]);
          catch (Exception ex) {
                 System.out.println("Exception");
          catch (NullPointerException npe) {
                 System.out.println("NullPointerException");
          }
    }


What is the result?
A. test 
B. Exception 
C. Compilation fails. 
D. NullPointerException
Correct Answer: C 
Explanation/Reference:
It gives the compilation error "Unreachable catch block for NullPointerException. It is already handled by the catch block for Exception" on line with the second catch.

QUESTION 14 Given:

    public static void main(String[] args) {
          for (int i = 0; i <= 10; i++) {
                 if (i > 6)
                       break;
          }
          System.out.println(i);
    }


What is the result?
A. 6 
B. 7 
C. 10 
D. 11 
E. Compilation fails. 
F. An exception is thrown at runtime.
 Correct Answer: E 
Explanation/Reference:
error on println line: "i cannot be resolved to a variable"

QUESTION 15 Given:
11.class X { public void foo() { System.out.print("X "); } } 
12. 
13.public class SubB extends X { 
14. public void foo() throws RuntimeException { 
15. super.foo(); 
16. if (true) throw new RuntimeException(); 
17. System.out.print("B "); 
18. } 
19. public static void main(String[] args) { 
20. new SubB().foo(); 
21. } 
22.}
What is the result?
A. X, followed by an Exception. 
B. No output, and an Exception is thrown. 
C. Compilation fails due to an error on line 14. 
D. Compilation fails due to an error on line 16. 
E. Compilation fails due to an error on line 17. 
F. X, followed by an Exception, followed by B.
Correct Answer: A 
Explanation/Reference:
X Exception in thread "main" java.lang.RuntimeException
at SubB.foo(SubB.java:5) at SubB.main(SubB.java:9)

QUESTION 16 Given:
   
    public void testIfA() {
          if (testIfB("True")) { // Linea 12
                 System.out.println("True");
          else {
                 System.out.println("Not true");
          }
    }

    public Boolean testIfB(String str) {
          return Boolean.valueOf(str); //Linea 19 
}


What is the result when method testIfA is invoked?
A. True 
B. Not true 
C. An exception is thrown at runtime. 
D. Compilation fails because of an error at line 12. 
E. Compilation fails because of an error at line 19.
Correct Answer: A 

QUESTION 17 Which can appropriately be thrown by a programmer using Java SE technology to create a desktop application?
A. ClassCastException 
B. NullPointerException 
C. NoClassDefFoundError 
D. NumberFormatException 
E. ArrayIndexOutOfBoundsException
Correct Answer: D 

QUESTION 18 Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)
A. int []x = {1,2,3,4,5};
for(int y = 0; y < 6; y++)
System.out.println(x[y]); 

B. static int[] x = {7,6,5,4};
static { x[1] = 8; x[4] = 3; } 

C. for(int y = 10; y < 10; y++)
doStuff(y); 
D. void doOne(int x) { doTwo(x); }
void doTwo(int y) { doThree(y); } void doThree(int z) { doTwo(z); } 

E. for(int x = 0; x < 1000000000; x++)
doStuff(x); F. void counter(int i) { counter(++i); }
Correct Answer: DF


QUESTION 19 Given:
    public static void main(String[] args) {
          Integer inew 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.
Correct Answer: A 

QUESTION 20 Given:
public class Tahiti {
    Tahiti t;

public static void main(String[] args) {
Tahiti t = new Tahiti(); Tahiti t2 = t.go(t); t2 = null; // more code here 11 }

    Tahiti go(Tahiti t) {
          Tahiti t1new Tahiti();
          Tahiti t2new Tahiti();
          t1.tt2;
          t2.tt1;
          t.tt2;
          return t1;
    }
}

When line 11 is reached, how many objects are eligible for garbage collection?
A. 0 
B. 1 
C. 2 
D. 3
E. Compilation fails.
Correct Answer: A 

QUESTION 21 Given:
public class Commander {
    public static void main(String[] args) {
          String myProp/* insert code here Linea 13 */ System.out.println(myProp);
    }
}


and the command line: java -Dprop.custom=gobstopper Commander
Which two, placed on line 13, will produce the output gobstopper? (Choose two.)
A. System.load("prop.custom"); 
B. System.getenv("prop.custom"); 
C. System.property("prop.custom"); 
D. System.getProperty("prop.custom"); 
E. System.getProperties().getProperty("prop.custom");
Correct Answer: DE 

QUESTION 22 Given: 
public class ItemTest {
    private final int id;

    public ItemTest(int id) {
          this.idid;
    }

    public void updateId(int newId) {
          idnewId;
    }

    public static void main(String[] args) {
          ItemTest fanew ItemTest(42);
          fa.updateId(69);
          System.out.println(fa.id);
    }
}


What is the result?
A. Compilation fails. 
B. An exception is thrown at runtime. 
C. The attribute id in the ItemTest object remains unchanged. 
D. The attribute id in the ItemTest object is modified to the new value. 
E. A new ItemTest object is created with the preferred value in the id attribute.
 Correct Answer: A 
Explanation/Reference:
The final field ItemTest.id cannot be assigned

QUESTION 23. A developer is creating a class Book, that needs to access class Paper. The Paper class is deployed in a JAR named myLib.jar. Which three, taken independently, will allow the developer to use the Paper class while compiling the Book class? (Choose three.)
A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar. 
B. The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar.. 
C. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/
myLib.jar/Paper.class. 
D. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/
myLib.jar. 
E. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - cp /foo/myLib.jar/
Paper Book.java. F. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d /foo/myLib.jar
Book.java G. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - classpath /foo/
myLib.jar Book.java
Correct Answer: BDG 

QUESTION 24 Given:
public class Yippee {
    public static void main(String[] args) {
          for (int x = 1; xargs.lengthx++) {
                 System.out.print(args[x] + " ");
          }
    }
}

and two separate command line invocations: java Yippee java Yippee 1 2 3 4
What is the result?
A. No output is produced. 1 2 3 
B. No output is produced. 2 3 4 
C. No output is produced. 1 2 3 4 
D. An exception is thrown at runtime. 1 2 3 
E. An exception is thrown at runtime. 2 3 4 
F. An exception is thrown at runtime. 1 2 3 4
Correct Answer: B 

QUESTION 25 Click the Exhibit button.
class Foo {
    private int x;

    public Foo(int x) {
          this.xx;
    }

    public void setX(int x) {
          this.xx;
    }

    public int getX() {
          return x;
    }
}

public class Gamma {
    static Foo fooBar(Foo foo) {
          foonew Foo(100);
          return foo;
    }

    public static void main(String[] args) {
          Foo foonew Foo(300);
          System.out.println(foo.getX() + "-");
          Foo fooFoofooBar(foo);
          System.out.println(foo.getX() + "-");
          System.out.println(fooFoo.getX() + "-");
          foofooBar(fooFoo);
          System.out.println(foo.getX() + "-");
          System.out.println(fooFoo.getX());
    }
}


What is the output of the program shown in the exhibit?
A. 300-100-100-100-100 
B. 300-300-100-100-100 
C. 300-300-300-100-100 
D. 300-300-300-300-100
Correct Answer: B 

QUESTION 26 Given classes defined in two different files:
1. package packageA; 
2. public class Message { 
3. String getText() { 
4. return "text"; 
5. } 
6. }
And:
1. package packageB; 2. 
3. public class XMLMessage extends packageA.Message { 
4. String getText() { 5. return "<msg>text</msg>"; 6. }

8. public static void main(String[] args) { 
9. System.out.println(new XMLMessage().getText()); 10. } 11.}
What is the result of executing XMLMessage.main?
A. text 
B. Compilation fails. 
C. <msg>text</msg> 
D. An exception is thrown at runtime.
Correct Answer: C 

QUESTION 27 Given: 
interface Fish { }
class Perch implements Fish {
}

class Walleye extends Perch {
}

class Bluegill {
}

public class Fisherman {
    public static void main(String[] args) {
          Fish fnew Walleye();
          Walleye wnew Walleye();
          Bluegill bnew Bluegill();
          if (f instanceof Perch)
                 System.out.print("f-p ");
          if (w instanceof Fish)
                 System.out.print("w-f ");
          if (b instanceof Fish)
                 System.out.print("b-f ");
    }
}


What is the result?
A. w-f 
B. f-p w-f 
C. w-f b-f 
D. f-p w-f b-f 
E. Compilation fails. 
F. An exception is thrown at runtime.
Correct Answer: B


QUESTION 28 Given:
1. package com.company.application;

3. public class MainClass { 
4. public static void main(String[] args) { 
5. } 
6. }
And MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH environment variable is set to "." (current directory). Which two java commands entered at the command line will run MainClass? (Choose two.)
A. java MainClass if run from the /apps directory 
B. java com.company.application.MainClass if run from the /apps directory 
C. java -classpath /apps com.company.application.MainClass if run from any directory 
D. java -classpath . MainClass if run from the /apps/com/company/application directory 
E. java -classpath /apps/com/company/application:. MainClass if run from the /apps directory 
F. java com.company.application.MainClass if run from the /apps/com/company/application directory
Correct Answer: BC 

QUESTION 29 Given class Foo {
static void alpha() {
/* more code here */ }
void beta() {
/* more code here */ } } Which two statements are true? (Choose two.)
A. Foo.beta() is a valid invocation of beta(). B. Foo.alpha() is a valid invocation of alpha(). C. Method beta() can directly call method alpha(). D. Method alpha() can directly call method beta().
Correct Answer: BC 

QUESTION 30 Given:
 1. public class TestSeven extends Thread { 
2. private static int x; 
3. public synchronized void doThings() { 
4. int current = x; 
5. current++; 
6. x = current; 
7. } 
8. public void run() { 
9. doThings(); 
10. } 
11.}
Which statement is true?
A. Compilation fails. 
B. An exception is thrown at runtime. 
C. Synchronizing the run() method would make the class thread-safe. 
D. The data in variable "x" are protected from concurrent access problems. 
E. Declaring the doThings() method as static would make the class thread-safe. 
F. Wrapping the statements within doThings() in a synchronized(new Object()) { } block would make the
class thread-safe.
Correct Answer: E 
eEdit
Must read for you :